You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2017/10/03 14:23:52 UTC

[15/35] brooklyn-server git commit: more testing of task cancel (in response to jenkins failure)

more testing of task cancel (in response to jenkins failure)


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/5e19dec5
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/5e19dec5
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/5e19dec5

Branch: refs/heads/master
Commit: 5e19dec5180cc22066f91a4c229974e09a9d1ac1
Parents: c1f78bb
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Sep 15 10:52:15 2017 +0100
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Sep 15 10:52:15 2017 +0100

----------------------------------------------------------------------
 .../util/core/task/BasicTasksFutureTest.java    | 21 ++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5e19dec5/core/src/test/java/org/apache/brooklyn/util/core/task/BasicTasksFutureTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/task/BasicTasksFutureTest.java b/core/src/test/java/org/apache/brooklyn/util/core/task/BasicTasksFutureTest.java
index 442813c..9d53532 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/task/BasicTasksFutureTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/task/BasicTasksFutureTest.java
@@ -182,21 +182,34 @@ public class BasicTasksFutureTest {
         // if cancel fires after submit but before it passes to the executor,
         // that needs handling separately; this doesn't guarantee this code path,
         // but it happens sometimes (and it should be handled)
+        
+        // have seen this fail once, not getting "before", but can't see why, may be spurious
         doTestCancelTriggersListenableFuture(Duration.ZERO);
     }
+    @Test
+    public void testCancelBeforeTriggersListenableFuture() throws Exception {
+        // if cancel fires after submit but before it passes to the executor,
+        // that needs handling separately; this doesn't guarantee this code path,
+        // but it happens sometimes (and it should be handled)
+        doTestCancelTriggersListenableFuture(Duration.millis(-50));
+    }
     public void doTestCancelTriggersListenableFuture(Duration delay) throws Exception {
         Task<String> t = waitForSemaphore(Duration.TEN_SECONDS, true, "x");
         addFutureListener(t, "before");
 
         Stopwatch watch = Stopwatch.createStarted();
-        ec.submit(t);
+        if (delay.isNegative()) {
+            new Thread(() -> { Time.sleep(delay.multiply(-1)); ec.submit(t); }).run(); 
+        } else {
+            ec.submit(t);
+        }
         
         addFutureListener(t, "during");
 
         log.info("test cancelling "+t+" ("+t.getClass()+") after "+delay);
-        // NB: two different code paths (callers to this method) for notifying futures 
-        // depending whether task is started 
-        Time.sleep(delay);
+        // NB: three different code paths (callers to this method) for notifying futures 
+        // depending whether task is started before, at, or after the cancel 
+        if (!delay.isNegative()) Time.sleep(delay);
 
         synchronized (data) {
             t.cancel(true);