Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bug20813: AGConnPoolClosingTest Session process remaining

tests-added:   none
tests-run:     java-bigger-test
performance:   no impact
release-notes: none, test only

This test was failing sometimes, not always.
Sleep for a few seconds before checking processes to give them
time to go away.

Change-Id: Ia39268de7c5fb98eae3f8bcc80d5e8ac85850502
Reviewed-on: https://gerrit.franz.com:9080/1956
Reviewed-by: Ahmon Dancy <dancy@franz.com>
Reviewed-by: Kevin Layer <layer@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
commit 9742b1d4a16d569c71d41de28560dd451fb2f97f 1 parent 6b4a69d
@mikehinchey mikehinchey authored dklayer committed
Showing with 39 additions and 9 deletions.
  1. +23 −0 src/test/Util.java
  2. +16 −9 src/test/pool/AGConnPoolClosingTest.java
View
23 src/test/Util.java
@@ -20,6 +20,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Random;
+import java.util.concurrent.Callable;
import java.util.zip.GZIPOutputStream;
import com.franz.util.Closer;
@@ -254,4 +255,26 @@ public long nextLong(long max) {
}
+ /**
+ * Call fn until it returns null or false.
+ * @return the last value from fn
+ */
+ public static <ReturnType> ReturnType waitFor(long sleep, long maxWait, Callable<ReturnType> fn) throws Exception {
+ long start = System.nanoTime();
+ while (true) {
+ ReturnType ret = fn.call();
+ if (ret == null || Boolean.FALSE.equals(ret)) {
+ return ret;
+ }
+ try {
+ Thread.sleep(sleep);
+ } catch (InterruptedException e) {
+ continue;
+ }
+ if ((System.nanoTime() - start) < maxWait) {
+ return ret;
+ }
+ }
+ }
+
}
View
25 src/test/pool/AGConnPoolClosingTest.java
@@ -12,6 +12,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -25,6 +26,7 @@
import test.AGAbstractTest;
import test.TestSuites;
+import test.Util;
import com.franz.agraph.pool.AGConnPool;
import com.franz.agraph.pool.AGConnProp;
@@ -94,16 +96,21 @@ public void run() {
}
close();
- Map<String, String> procs = processes();
- for (Entry<String, String> entry : procs.entrySet()) {
- if (entry.getValue().contains("test.pool.AGConnPoolClosingTest")
- && entry.getValue().contains("session")) {
- log.error("Session: " + entry);
- Assert.fail("Session process remaining: " + procs);
- } else {
- log.debug("Process: " + entry);
+ long start = System.nanoTime();
+ Map<String, String> procs = Util.waitFor(TimeUnit.SECONDS.toMillis(1), TimeUnit.SECONDS.toMillis(30),
+ new Callable<Map<String, String>>() {
+ public Map<String, String> call() throws Exception {
+ Map<String, String> procs = processes();
+ for (Entry<String, String> entry : procs.entrySet()) {
+ if (entry.getValue().contains("test.pool.AGConnPoolClosingTest")
+ && entry.getValue().contains("session")) {
+ return procs;
+ }
+ }
+ return null;
}
- }
+ });
+ Assert.assertNull("Session process " + TimeUnit.NANOSECONDS.toSeconds((System.nanoTime() - start)) + " seconds after closing.", procs);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.