Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in handling non-unique filenames by sorting via hash #122

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.askimed.nf.test.lang.channels;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Map;

import com.askimed.nf.test.lang.extensions.PathExtension;
import com.askimed.nf.test.util.AnsiColors;

public class ChannelItemComparator implements Comparator<Object> {
Expand Down Expand Up @@ -74,14 +75,30 @@ private boolean isPath(Object a) {

@SuppressWarnings({ "rawtypes" })
private int compareMaps(Map a, Map b) {
// since we converted all nested maps to treemaps, toString returns keys sorted in deterministic order.
// since we converted all nested maps to treemaps, toString returns keys sorted
// in deterministic order.
return compareStrings(a.toString(), b.toString());
}

public int comparePaths(String a, String b) {
String name1 = new File(a).getName();
String name2 = new File(b).getName();
return name1.compareTo(name2);
// sort path by filename
Path path1 = Path.of(a);
Path path2 = Path.of(b);
String name1 = path1.getFileName().toString();
String name2 = path2.getFileName().toString();
int result = name1.compareTo(name2);
if (result != 0) {
return result;
}
// filenames are equal -> sort by hash to get deterministic order
try {
String hash1 = PathExtension.getMd5(path1);
String hash2 = PathExtension.getMd5(path2);
return hash1.compareTo(hash2);
} catch (Exception e) {
throw new RuntimeException(e);
}

}

public int compareStrings(String a, String b) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/askimed/nf/test/lang/WorkflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,13 @@ public void testHangingWorkflowIssue57() throws Exception {

}

@Test
public void testWorkflowNonUniqueFilenames() throws Exception {

App app = new App();
int exitCode = app.run(new String[] { "test", "test-data/workflow/non-unique-filenames/main.nf.test"});
assertEquals(0, exitCode);

}

}
22 changes: 22 additions & 0 deletions test-data/workflow/non-unique-filenames/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env nextflow

process WRITE_VERSION {
input:
val version

output:
path "*.txt", emit: versions

script:
"""
echo ${version} > version.txt
"""
}

workflow DUPLICATE_FILENAMES {
take: things
main:
WRITE_VERSION(things)
emit:
versions = WRITE_VERSION.out.versions
}
21 changes: 21 additions & 0 deletions test-data/workflow/non-unique-filenames/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
nextflow_workflow {

name "Test duplicate filenames in one channel"
script "./main.nf"
workflow "DUPLICATE_FILENAMES"

test("Should run without failures") {
when {
workflow {
"""
input[0] = Channel.of(1..50)
"""
}
}

then {
assert workflow.success
assert snapshot(workflow.out).match()
}
}
}
113 changes: 113 additions & 0 deletions test-data/workflow/non-unique-filenames/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"Should run without failures": {
"content": [
{
"0": [
"version.txt:md5,08c61f3fd48f12fa7c88a7f5fd01df3d",
"version.txt:md5,166d77ac1b46a1ec38aa35ab7e628ab5",
"version.txt:md5,1dcca23355272056f04fe8bf20edfce0",
"version.txt:md5,21fa2e849284bf7681c37a8b565bd934",
"version.txt:md5,22cab69bca05d296a2d779a52cdee643",
"version.txt:md5,26ab0db90d72e28ad0ba1e22ee510510",
"version.txt:md5,2737b49252e2a4c0fe4c342e92b13285",
"version.txt:md5,2a52a5e65fc3c43f409550dfad1f904f",
"version.txt:md5,2a53da1a6fbfc0bafdd96b0a2ea29515",
"version.txt:md5,2fc57d6f63a9ee7e2f21a26fa522e3b6",
"version.txt:md5,31d30eea8d0968d6458e0ad0027c9f80",
"version.txt:md5,367764329430db34be92fd14a7a770ee",
"version.txt:md5,3bb50ff8eeb7ad116724b56a820139fa",
"version.txt:md5,48a24b70a0b376535542b996af517398",
"version.txt:md5,4a5c26d88c514a23bf15654abd83adb1",
"version.txt:md5,4d095eeac8ed659b1ce69dcef32ed0dc",
"version.txt:md5,4f89a0f6c113ae3ff279af1e6c6286bb",
"version.txt:md5,4fbafd6948b6529caa2b78e476359875",
"version.txt:md5,50a2fabfdd276f573ff97ace8b11c5f4",
"version.txt:md5,51a6d96331d5eaa300358c7a0faf168d",
"version.txt:md5,59885ebc737617addaaf0cb8090203fc",
"version.txt:md5,5b6b41ed9b343fed9cd05a66d36650f0",
"version.txt:md5,649ee93d50739c656e94ec88a32c7ffe",
"version.txt:md5,66a7c1d5cb75ef2542524d888fd32f4a",
"version.txt:md5,6d7fce9fee471194aa8b5b6e47267f03",
"version.txt:md5,6eb5cefde6fcb8463cea70880a44eb98",
"version.txt:md5,7c5aba41f53293b712fd86d08ed5b36e",
"version.txt:md5,7c67493bd72ceff21059c3d924d17518",
"version.txt:md5,84bc3da1b3e33a18e8d5e1bdd7a18d7a",
"version.txt:md5,87aa60e6e440a6656bc74eb20476d662",
"version.txt:md5,8c9eb686bf3eb5bd83d9373eadf6504b",
"version.txt:md5,90e2a51705594d033a3abe9d77b2b7ad",
"version.txt:md5,93e50d72ab294091a81d828459019eba",
"version.txt:md5,9ae0ea9e3c9c6e1b9b6252c8395efdc1",
"version.txt:md5,a75f5a8337c6699916182b6f7c10d7a9",
"version.txt:md5,aa6ed9e0f26a6eba784aae8267df1951",
"version.txt:md5,b026324c6904b2a9cb4b88d6d61c81d1",
"version.txt:md5,b0771132ab2531a40c9941375ed8e290",
"version.txt:md5,bb743fc2a7213949f25593c51cbee64f",
"version.txt:md5,bda81ba88c634b46394ead43aff31ad5",
"version.txt:md5,c30f7472766d25af1dc80b3ffc9a58c7",
"version.txt:md5,cf4278314ef8e4b996e1b798d8eb92cf",
"version.txt:md5,d3a57c7e953913944c76009357469568",
"version.txt:md5,d5b4c7d9b06b60a7846c4529834c9812",
"version.txt:md5,dbbf8220893d497d403bb9cdf49db7a4",
"version.txt:md5,e760668b6273d38c832c153fde5725da",
"version.txt:md5,f0287f33eba7192e2a9c6a14f829aa1a",
"version.txt:md5,fa84f696e31d07f55cd45cc3c9e52f3b",
"version.txt:md5,fd1bc138d22d4f78150c6e808345c2cc",
"version.txt:md5,fe9d26c3e620eeb69bd166c8be89fb8f"
],
"versions": [
"version.txt:md5,08c61f3fd48f12fa7c88a7f5fd01df3d",
"version.txt:md5,166d77ac1b46a1ec38aa35ab7e628ab5",
"version.txt:md5,1dcca23355272056f04fe8bf20edfce0",
"version.txt:md5,21fa2e849284bf7681c37a8b565bd934",
"version.txt:md5,22cab69bca05d296a2d779a52cdee643",
"version.txt:md5,26ab0db90d72e28ad0ba1e22ee510510",
"version.txt:md5,2737b49252e2a4c0fe4c342e92b13285",
"version.txt:md5,2a52a5e65fc3c43f409550dfad1f904f",
"version.txt:md5,2a53da1a6fbfc0bafdd96b0a2ea29515",
"version.txt:md5,2fc57d6f63a9ee7e2f21a26fa522e3b6",
"version.txt:md5,31d30eea8d0968d6458e0ad0027c9f80",
"version.txt:md5,367764329430db34be92fd14a7a770ee",
"version.txt:md5,3bb50ff8eeb7ad116724b56a820139fa",
"version.txt:md5,48a24b70a0b376535542b996af517398",
"version.txt:md5,4a5c26d88c514a23bf15654abd83adb1",
"version.txt:md5,4d095eeac8ed659b1ce69dcef32ed0dc",
"version.txt:md5,4f89a0f6c113ae3ff279af1e6c6286bb",
"version.txt:md5,4fbafd6948b6529caa2b78e476359875",
"version.txt:md5,50a2fabfdd276f573ff97ace8b11c5f4",
"version.txt:md5,51a6d96331d5eaa300358c7a0faf168d",
"version.txt:md5,59885ebc737617addaaf0cb8090203fc",
"version.txt:md5,5b6b41ed9b343fed9cd05a66d36650f0",
"version.txt:md5,649ee93d50739c656e94ec88a32c7ffe",
"version.txt:md5,66a7c1d5cb75ef2542524d888fd32f4a",
"version.txt:md5,6d7fce9fee471194aa8b5b6e47267f03",
"version.txt:md5,6eb5cefde6fcb8463cea70880a44eb98",
"version.txt:md5,7c5aba41f53293b712fd86d08ed5b36e",
"version.txt:md5,7c67493bd72ceff21059c3d924d17518",
"version.txt:md5,84bc3da1b3e33a18e8d5e1bdd7a18d7a",
"version.txt:md5,87aa60e6e440a6656bc74eb20476d662",
"version.txt:md5,8c9eb686bf3eb5bd83d9373eadf6504b",
"version.txt:md5,90e2a51705594d033a3abe9d77b2b7ad",
"version.txt:md5,93e50d72ab294091a81d828459019eba",
"version.txt:md5,9ae0ea9e3c9c6e1b9b6252c8395efdc1",
"version.txt:md5,a75f5a8337c6699916182b6f7c10d7a9",
"version.txt:md5,aa6ed9e0f26a6eba784aae8267df1951",
"version.txt:md5,b026324c6904b2a9cb4b88d6d61c81d1",
"version.txt:md5,b0771132ab2531a40c9941375ed8e290",
"version.txt:md5,bb743fc2a7213949f25593c51cbee64f",
"version.txt:md5,bda81ba88c634b46394ead43aff31ad5",
"version.txt:md5,c30f7472766d25af1dc80b3ffc9a58c7",
"version.txt:md5,cf4278314ef8e4b996e1b798d8eb92cf",
"version.txt:md5,d3a57c7e953913944c76009357469568",
"version.txt:md5,d5b4c7d9b06b60a7846c4529834c9812",
"version.txt:md5,dbbf8220893d497d403bb9cdf49db7a4",
"version.txt:md5,e760668b6273d38c832c153fde5725da",
"version.txt:md5,f0287f33eba7192e2a9c6a14f829aa1a",
"version.txt:md5,fa84f696e31d07f55cd45cc3c9e52f3b",
"version.txt:md5,fd1bc138d22d4f78150c6e808345c2cc",
"version.txt:md5,fe9d26c3e620eeb69bd166c8be89fb8f"
]
}
],
"timestamp": "2023-09-23T09:30:55.706829"
}
}
Loading