changeset 1051:2f9c7421ec8e

7901119: Sync iterations are broken by CODETOOLS-7901118, and SyncIterNotOnlyMeasurementTest is @Ignore-d
author shade
date Fri, 05 Dec 2014 00:39:54 +0300
parents adb6047266d8
children 23dfeb5ab926
files jmh-core-it/src/test/java/org/openjdk/jmh/it/synciter/SyncIterNotOnlyMeasurementTest.java jmh-core/src/main/java/org/openjdk/jmh/runner/InfraControl.java jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java
diffstat 3 files changed, 55 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core-it/src/test/java/org/openjdk/jmh/it/synciter/SyncIterNotOnlyMeasurementTest.java	Thu Dec 04 19:45:31 2014 +0300
+++ b/jmh-core-it/src/test/java/org/openjdk/jmh/it/synciter/SyncIterNotOnlyMeasurementTest.java	Fri Dec 05 00:39:54 2014 +0300
@@ -25,13 +25,13 @@
 package org.openjdk.jmh.it.synciter;
 
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
+import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.Fork;
-import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.Level;
 import org.openjdk.jmh.annotations.Measurement;
 import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
 import org.openjdk.jmh.annotations.State;
 import org.openjdk.jmh.annotations.TearDown;
 import org.openjdk.jmh.annotations.Threads;
@@ -47,7 +47,12 @@
 @State(Scope.Benchmark)
 public class SyncIterNotOnlyMeasurementTest {
 
-    private boolean inMeasurementLoopOnly = true;
+    private boolean inMeasurementLoopOnly;
+
+    @Setup(Level.Trial)
+    public void setup() {
+        inMeasurementLoopOnly = true;
+    }
 
     @TearDown(Level.Trial)
     public void check() {
@@ -73,16 +78,31 @@
     }
 
     @Test
-    @Ignore // this test is probabilistic
     public void invokeAPI() throws RunnerException {
-        for (int c = 0; c < Fixtures.repetitionCount(); c++) {
-            Options opt = new OptionsBuilder()
-                    .include(Fixtures.getTestMask(this.getClass()))
-                    .shouldFailOnError(true)
-                    .syncIterations(true)
-                    .build();
-            new Runner(opt).run();
+        // This test is probabilistic, and it can fail sometimes, but not all the time.
+
+        Options opt = new OptionsBuilder()
+                .include(Fixtures.getTestMask(this.getClass()))
+                .shouldFailOnError(true)
+                .syncIterations(true)
+                .build();
+
+        final int trials = 200;
+
+        RunnerException last = null;
+        for (int c = 0; c < trials; c++) {
+            try {
+                new Runner(opt).run();
+
+                // no assert, yay, we can break away now
+                return;
+            } catch (RunnerException e) {
+                last = e;
+            }
         }
+
+        // we consistently throw exceptions, re-throw the last one
+        throw last;
     }
 
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/InfraControl.java	Thu Dec 04 19:45:31 2014 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/InfraControl.java	Fri Dec 05 00:39:54 2014 +0300
@@ -155,12 +155,8 @@
         shouldSynchIterations = benchmarkParams.shouldSynchIterations();
         threads = benchmarkParams.getThreads();
 
-        if (!shouldSynchIterations) {
-            warmupShouldWait = false;
-            warmdownShouldWait = false;
-            warmupDone.countDown();
-            warmdownDone.countDown();
-        }
+        warmupShouldWait = shouldSynchIterations;
+        warmdownShouldWait = shouldSynchIterations;
 
         this.preSetup = preSetup;
         this.preTearDown = preTearDown;
@@ -196,6 +192,26 @@
         }
     }
 
+    public void awaitWarmupReady() {
+        if (warmupShouldWait) {
+            try {
+                warmupDone.await();
+            } catch (InterruptedException e) {
+                // ignore
+            }
+        }
+    }
+
+    public void awaitWarmdownReady() {
+        if (warmdownShouldWait) {
+            try {
+                warmdownDone.await();
+            } catch (InterruptedException e) {
+                // ignore
+            }
+        }
+    }
+
     public String getParam(String name) {
         String param = benchmarkParams.getParam(name);
         if (param == null) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java	Thu Dec 04 19:45:31 2014 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java	Fri Dec 05 00:39:54 2014 +0300
@@ -94,11 +94,7 @@
         }
 
         // wait for all workers to transit to measurement
-        try {
-            control.warmupDone.await();
-        } catch (InterruptedException e) {
-            // ignore
-        }
+        control.awaitWarmupReady();
 
         // wait for the iteration time to expire
         switch (benchmarkParams.getMode()) {
@@ -117,11 +113,7 @@
         control.isDone = true;
 
         // wait for all workers to transit to teardown
-        try {
-            control.warmdownDone.await();
-        } catch (InterruptedException e) {
-            // ignore
-        }
+        control.awaitWarmdownReady();
 
         // Wait for the result, continuously polling the worker threads.
         // The abrupt exception in any worker will float up here.