flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srich...@apache.org
Subject flink git commit: [FLINK-8040] [tests] Fix test instability in ResourceGuardTest (cherry picked from commit ad8ef6d)
Date Mon, 13 Nov 2017 12:51:31 GMT
Repository: flink
Updated Branches:
  refs/heads/release-1.4 431ae36f7 -> e2b92f22c


[FLINK-8040] [tests] Fix test instability in ResourceGuardTest
(cherry picked from commit ad8ef6d)


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/e2b92f22
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/e2b92f22
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/e2b92f22

Branch: refs/heads/release-1.4
Commit: e2b92f22c2686f8d842d371a17c36c5d28f9b247
Parents: 431ae36
Author: Stefan Richter <s.richter@data-artisans.com>
Authored: Mon Nov 13 11:50:07 2017 +0100
Committer: Stefan Richter <s.richter@data-artisans.com>
Committed: Mon Nov 13 13:50:46 2017 +0100

----------------------------------------------------------------------
 .../apache/flink/util/ResourceGuardTest.java    | 53 +++++++++++++-------
 1 file changed, 34 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/e2b92f22/flink-core/src/test/java/org/apache/flink/util/ResourceGuardTest.java
----------------------------------------------------------------------
diff --git a/flink-core/src/test/java/org/apache/flink/util/ResourceGuardTest.java b/flink-core/src/test/java/org/apache/flink/util/ResourceGuardTest.java
index 98aae4d..ade8d0f 100644
--- a/flink-core/src/test/java/org/apache/flink/util/ResourceGuardTest.java
+++ b/flink-core/src/test/java/org/apache/flink/util/ResourceGuardTest.java
@@ -53,30 +53,37 @@ public class ResourceGuardTest extends TestLogger {
 	@Test
 	public void testCloseBlockIfAcquired() throws Exception {
 		ResourceGuard resourceGuard = new ResourceGuard();
-		ResourceGuard.Lease lease_1 = resourceGuard.acquireResource();
+		ResourceGuard.Lease lease = resourceGuard.acquireResource();
 		AtomicBoolean checker = new AtomicBoolean(true);
 
 		Thread closerThread = new Thread() {
 			@Override
 			public void run() {
-				try {
-					// this line should block until all acquires are matched by releases.
-					resourceGuard.close();
-					checker.set(false);
-				} catch (Exception ignore) {
-					checker.set(false);
-				}
+				// this line should block until all acquires are matched by releases.
+				resourceGuard.close();
+				checker.set(false);
 			}
 		};
 
 		closerThread.start();
 
-		ResourceGuard.Lease lease_2 = resourceGuard.acquireResource();
-		lease_2.close();
+		// we wait until the close()-call in the other thread happened.
+		while (!resourceGuard.isClosed()) {
+			Thread.yield();
+		}
+
+		// validate that the close()-call is still blocked.
 		Assert.assertTrue(checker.get());
 
-		// this matches the first acquire and will unblock the close.
-		lease_1.close();
+		// validate that the closed-status is already effective.
+		try {
+			resourceGuard.acquireResource();
+			Assert.fail("Resource guard is expected to be already closed.");
+		} catch (IOException ignore) {
+		}
+
+		// this matches the first acquire and will unblock the close()-call in the other thread.
+		lease.close();
 		closerThread.join(60_000);
 		Assert.assertFalse(checker.get());
 	}
@@ -90,21 +97,29 @@ public class ResourceGuardTest extends TestLogger {
 		Thread closerThread = new Thread() {
 			@Override
 			public void run() {
-				try {
-					// this line should block until all acquires are matched by releases.
-					resourceGuard.close();
-					checker.set(false);
-				} catch (Exception ignore) {
-					checker.set(false);
-				}
+				// this line should block until all acquires are matched by releases.
+				resourceGuard.close();
+				checker.set(false);
 			}
 		};
 
 		closerThread.start();
+
+		// we wait until the close()-call in the other thread happened.
+		while (!resourceGuard.isClosed()) {
+			Thread.yield();
+		}
+
+		// attempt to unblock the resource guard via interrupt.
 		closerThread.interrupt();
 
+		// wait some time.
+		closerThread.join(100);
+
+		// check that unblock through interrupting failed.
 		Assert.assertTrue(checker.get());
 
+		// proper unblocking by closing the lease.
 		lease.close();
 		closerThread.join(60_000);
 		Assert.assertFalse(checker.get());


Mime
View raw message