Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 03C81200CFC for ; Thu, 28 Sep 2017 16:23:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 021D31609CD; Thu, 28 Sep 2017 14:23:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 48E831609C2 for ; Thu, 28 Sep 2017 16:23:05 +0200 (CEST) Received: (qmail 989 invoked by uid 500); 28 Sep 2017 14:23:04 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 961 invoked by uid 99); 28 Sep 2017 14:23:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Sep 2017 14:23:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DC4EFF3261; Thu, 28 Sep 2017 14:23:03 +0000 (UTC) From: ahgittin To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #816: Tasks code improvements - prep for better... Content-Type: text/plain Message-Id: <20170928142303.DC4EFF3261@git1-us-west.apache.org> Date: Thu, 28 Sep 2017 14:23:03 +0000 (UTC) archived-at: Thu, 28 Sep 2017 14:23:06 -0000 Github user ahgittin commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/816#discussion_r141632615 --- Diff: core/src/test/java/org/apache/brooklyn/util/core/task/BasicTasksFutureTest.java --- @@ -174,29 +175,53 @@ public T call() { } @Test - public void testCancelAfterStartTriggersListenableFuture() throws Exception { - doTestCancelTriggersListenableFuture(Duration.millis(50)); + public void testCancelAfterStartTriggersListenableFutureDynamic() throws Exception { + doTestCancelTriggersListenableFuture(Duration.millis(50), true); } @Test - public void testCancelImmediateTriggersListenableFuture() throws Exception { + public void testCancelImmediateTriggersListenableFutureDynamic() 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.ZERO); + // that needs handling separately as it falls into an edge where the future is set and cancelled + // so the executor won't run it, and our wrapper logic doesn't apply; + // this test doesn't guarantee this code path, but makes it likely enough it happens once in a while. + doTestCancelTriggersListenableFuture(Duration.ZERO, true); } - public void doTestCancelTriggersListenableFuture(Duration delay) throws Exception { - Task t = waitForSemaphore(Duration.TEN_SECONDS, true, "x"); + @Test + public void testCancelBeforeTriggersListenableFutureDynamic() throws Exception { + doTestCancelTriggersListenableFuture(Duration.millis(-50), true); + } + @Test + public void testCancelAfterStartTriggersListenableFutureSimple() throws Exception { + doTestCancelTriggersListenableFuture(Duration.millis(50), true); + } + @Test + public void testCancelImmediateTriggersListenableFutureSimple() throws Exception { + doTestCancelTriggersListenableFuture(Duration.ZERO, false); + } + @Test + public void testCancelBeforeTriggersListenableFutureSimple() throws Exception { + doTestCancelTriggersListenableFuture(Duration.millis(-50), false); + } + public void doTestCancelTriggersListenableFuture(Duration delay, boolean dynamic) throws Exception { --- End diff -- good idea ---