From 296bbcdb2781e88e34c3552f4c6ded1d03544879 Mon Sep 17 00:00:00 2001 From: Yang Xia <55853655+xiazcy@users.noreply.github.com> Date: Tue, 5 Dec 2023 13:51:46 -0800 Subject: [PATCH] Fix flaky traversal test due to duplicated key generated for project step (#2361) special case project traversal test to makes sure random string args generated are unique --- .../traversal/dsl/graph/GraphTraversalTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalTest.java index 84997e613b8..422ae12ab9b 100644 --- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalTest.java +++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalTest.java @@ -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];