You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/05/18 13:11:20 UTC
[13/16] incubator-tinkerpop git commit: TINKERPOP-1242 Tried to
harden ScriptEngineTest to prevent random fail
TINKERPOP-1242 Tried to harden ScriptEngineTest to prevent random fail
There seemed to be only one test that might have the potential for some sort of hanging scenario. Made some modifications there to improve reliability. Removed a call to Thread.yield() which I think went in there under a change to get the test "better" under windows - hoping the CountDownLatch will do a better job in keeping that reliable and working on Windows. CTR
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/6148e336
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/6148e336
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/6148e336
Branch: refs/heads/TINKERPOP-1274
Commit: 6148e3364c934f9d33d35ac616686915968d50bf
Parents: 0a34d2d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon May 16 14:14:14 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon May 16 14:14:14 2016 -0400
----------------------------------------------------------------------
.../groovy/engine/ScriptEnginesTest.java | 25 ++++++++++++++++----
1 file changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/6148e336/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEnginesTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEnginesTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEnginesTest.java
index 9a7e1bf..3a4b233 100644
--- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEnginesTest.java
+++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/engine/ScriptEnginesTest.java
@@ -33,6 +33,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
@@ -169,9 +171,11 @@ public class ScriptEnginesTest {
final AtomicInteger successes = new AtomicInteger(0);
final AtomicInteger failures = new AtomicInteger(0);
+ final CountDownLatch latch = new CountDownLatch(1);
final Thread threadImport = new Thread(() -> {
engines.addImports(imports);
+ latch.countDown();
});
// issue 1000 scripts in one thread using a class that isn't imported. this will result in failure.
@@ -181,11 +185,23 @@ public class ScriptEnginesTest {
final Thread threadEvalAndTriggerImport = new Thread(() ->
IntStream.range(0, 1000).forEach(i -> {
try {
+
engines.eval("Color.BLACK", new SimpleBindings(), "gremlin-groovy");
successes.incrementAndGet();
} catch (Exception ex) {
- if (failures.incrementAndGet() == 500) threadImport.start();
- Thread.yield();
+ // stop the failures halfway and allow the import thread to start
+ if (failures.incrementAndGet() == 500) {
+ threadImport.start();
+
+ // block until the import occurs
+ try {
+ latch.await(30000, TimeUnit.MILLISECONDS);
+ } catch (Exception inner) {
+ // this test should fail given that the nubmer of asserts for successes will not implement
+ // appropriately if this RuntimeException is thrown.
+ throw new RuntimeException(inner);
+ }
+ }
}
})
);
@@ -193,10 +209,9 @@ public class ScriptEnginesTest {
threadEvalAndTriggerImport.start();
threadEvalAndTriggerImport.join();
- threadImport.join();
- assertTrue("Success: " + successes.intValue() + " - Failures: " + failures.intValue(), successes.intValue() > 0);
- assertTrue("Success: " + successes.intValue() + " - Failures: " + failures.intValue(), failures.intValue() >= 500);
+ assertTrue("Success: " + successes.intValue() + " - Success: " + failures.intValue(), successes.intValue() == 500);
+ assertTrue("Failures: " + successes.intValue() + " - Failures: " + failures.intValue(), failures.intValue() == 500);
engines.close();
}