Skip to content

Commit

Permalink
Fix flaky traversal test due to duplicated key generated for project …
Browse files Browse the repository at this point in the history
…step (apache#2361)

special case project traversal test to makes sure random string args generated are unique
  • Loading branch information
xiazcy authored Dec 5, 2023
1 parent 636b49d commit 296bbcd
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ else if (stepMethod.getName().equals("to") || stepMethod.getName().equals("from"
}
} else if (stepMethod.getName().equals("math")) {
list.add(arguments[0] = random.nextInt(100) + " + " + random.nextInt(100));
} else if (stepMethod.getName().equals("project")) {
// project has two arguments [String, String[]]
list.add(arguments[0] = randomString(random));
arguments[1] = new String[random.nextInt(10) + 1];
for (int j = 0; j < ((String[]) arguments[1]).length; j++) {
((String[]) arguments[1])[j] = arguments[0] + randomString(random); // adds argument[0] to avoid getting its duplicate in argument[1]
}
// remove duplicates in argument[1] if any
arguments[1] = Arrays.stream((String[]) arguments[1]).distinct().toArray(String[]::new);
list.addAll(Arrays.asList((String[]) arguments[1]));
} else {
for (int i = 0; i < stepMethod.getParameterTypes().length; i++) {
final Class<?> type = stepMethod.getParameterTypes()[i];
Expand Down

0 comments on commit 296bbcd

Please sign in to comment.