From 1b45bd1a19c0dd3dc0bacae86134f3686036a436 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Thu, 25 Feb 2016 17:24:47 -0800 Subject: [PATCH] extending timeouts for travis Travis seems to want more time to do things. Maybe. Maybe there are other problems too! --- .../jj/http/server/EmbeddedHttpResponse.java | 6 +-- test/src/main/java/jj/testing/Latch.java | 46 +++++++++++++++++++ .../jj/testing/ServerLifecycleStatement.java | 2 +- .../configuration/ConfigurationAddedTest.java | 4 +- .../ConfigurationSystemTest.java | 4 +- .../StylesheetResourceIntegrationTest.java | 8 ++-- .../client/HttpClientIntegrationTest.java | 4 +- .../http/server/EmbeddedHttpServerTest.java | 5 +- .../jj/jasmine/JasmineIntegrationTest.java | 8 ++-- .../java/jj/repl/ReplIntegrationTest.java | 6 +-- .../ResourceSystemIntegrationTest.java | 6 +-- .../ScriptEnvironmentIntegrationTest.java | 12 ++--- .../java/jj/testing/BasicServingTest.java | 5 +- .../java/jj/testing/SystemScriptsTest.java | 5 +- 14 files changed, 82 insertions(+), 39 deletions(-) create mode 100644 test/src/main/java/jj/testing/Latch.java diff --git a/test/src/main/java/jj/http/server/EmbeddedHttpResponse.java b/test/src/main/java/jj/http/server/EmbeddedHttpResponse.java index 593d7daf..80d4e0e4 100644 --- a/test/src/main/java/jj/http/server/EmbeddedHttpResponse.java +++ b/test/src/main/java/jj/http/server/EmbeddedHttpResponse.java @@ -22,10 +22,10 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.util.ReferenceCountUtil; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import jj.http.server.EmbeddedHttpServer.ResponseReady; +import jj.testing.Latch; /** * @author jason @@ -35,7 +35,7 @@ public class EmbeddedHttpResponse { private final ResponseReady responseReady; - private final CountDownLatch responded = new CountDownLatch(1); + private final Latch responded = new Latch(1); volatile Throwable error; @@ -59,7 +59,7 @@ private void checkError() throws Throwable { public EmbeddedHttpResponse await(long time, TimeUnit unit) throws Throwable { if (!responded.await(time, unit)) { - throw new AssertionError("timed out"); + throw new AssertionError("timed out in " + time + " " + unit); } checkError(); diff --git a/test/src/main/java/jj/testing/Latch.java b/test/src/main/java/jj/testing/Latch.java new file mode 100644 index 00000000..6a2f5da1 --- /dev/null +++ b/test/src/main/java/jj/testing/Latch.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 Jason Miller + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package jj.testing; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * Integration test latch that waits additional time when running on travis CI + * @author Jason Miller + */ +public class Latch { + + private final CountDownLatch latch; + + public Latch(int count) { + latch = new CountDownLatch(count); + } + + public void countDown() { + latch.countDown(); + } + + public long getCount() { + return latch.getCount(); + } + + public boolean await(long timeout, TimeUnit unit) throws InterruptedException { + long timeoutMillis = TimeUnit.MILLISECONDS.convert(timeout, unit); + timeoutMillis += "true".equals(System.getenv("TRAVIS")) ? 2000 : 0; + return latch.await(timeoutMillis, TimeUnit.MILLISECONDS); + } +} diff --git a/test/src/main/java/jj/testing/ServerLifecycleStatement.java b/test/src/main/java/jj/testing/ServerLifecycleStatement.java index e59d9e00..dc147e14 100644 --- a/test/src/main/java/jj/testing/ServerLifecycleStatement.java +++ b/test/src/main/java/jj/testing/ServerLifecycleStatement.java @@ -38,7 +38,7 @@ public class ServerLifecycleStatement extends JibbrJabbrTestStatement { private final JJServerLifecycle lifecycle; private final Logger testLog; private final Description description; - private final CountDownLatch configured = new CountDownLatch(1); + private final Latch configured = new Latch(1); @Inject ServerLifecycleStatement( diff --git a/test/src/test/java/jj/configuration/ConfigurationAddedTest.java b/test/src/test/java/jj/configuration/ConfigurationAddedTest.java index 56510c12..b40295eb 100644 --- a/test/src/test/java/jj/configuration/ConfigurationAddedTest.java +++ b/test/src/test/java/jj/configuration/ConfigurationAddedTest.java @@ -21,6 +21,7 @@ import jj.event.Subscriber; import jj.jasmine.JasmineConfiguration; import jj.testing.JibbrJabbrTestServer; +import jj.testing.Latch; import org.junit.After; import org.junit.Rule; import org.junit.Test; @@ -31,7 +32,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardOpenOption; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import static org.hamcrest.core.Is.is; @@ -55,7 +55,7 @@ public class ConfigurationAddedTest { @Inject JasmineConfiguration jasmineConfiguration; - private final CountDownLatch latch = new CountDownLatch(2); + private final Latch latch = new Latch(2); @Listener void on(ConfigurationLoaded event) { diff --git a/test/src/test/java/jj/configuration/ConfigurationSystemTest.java b/test/src/test/java/jj/configuration/ConfigurationSystemTest.java index 6d275e26..a1dde9b1 100644 --- a/test/src/test/java/jj/configuration/ConfigurationSystemTest.java +++ b/test/src/test/java/jj/configuration/ConfigurationSystemTest.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.concurrent.CountDownLatch; import javax.inject.Inject; import javax.inject.Singleton; @@ -48,6 +47,7 @@ import jj.script.ScriptError; import jj.testing.JibbrJabbrTestServer; +import jj.testing.Latch; import org.junit.Rule; import org.junit.Test; @@ -92,7 +92,7 @@ static String httpServerSocket(String key) { private LoggingConfiguration loggingConfiguration; volatile boolean loaded; - final CountDownLatch loadedLatch = new CountDownLatch(1); + final Latch loadedLatch = new Latch(1); volatile boolean failed; @Listener diff --git a/test/src/test/java/jj/css/StylesheetResourceIntegrationTest.java b/test/src/test/java/jj/css/StylesheetResourceIntegrationTest.java index ec376f01..ad8188e7 100644 --- a/test/src/test/java/jj/css/StylesheetResourceIntegrationTest.java +++ b/test/src/test/java/jj/css/StylesheetResourceIntegrationTest.java @@ -23,7 +23,6 @@ import java.nio.file.Files; import java.nio.file.Paths; -import java.util.concurrent.CountDownLatch; import javax.inject.Inject; @@ -36,6 +35,7 @@ import jj.resource.ResourceLoader; import jj.testing.JibbrJabbrTestServer; +import jj.testing.Latch; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -55,7 +55,7 @@ public class StylesheetResourceIntegrationTest { StylesheetResource stylesheet; - CountDownLatch latch; + Latch latch; @Listener void on(ResourceLoaded event) { @@ -68,7 +68,7 @@ void on(ResourceLoaded event) { @Before public void before() { stylesheet = null; - latch = new CountDownLatch(1); + latch = new Latch(1); } @Test @@ -98,7 +98,7 @@ public void testCss() throws Exception { @Test public void testReplacements() throws Exception { - latch = new CountDownLatch(2); // we want two! + latch = new Latch(2); // we want two! resourceLoader.loadResource(StylesheetResource.class, Virtual, "replacement.css"); assertTrue("timed out", latch.await(2, SECONDS)); diff --git a/test/src/test/java/jj/http/client/HttpClientIntegrationTest.java b/test/src/test/java/jj/http/client/HttpClientIntegrationTest.java index b183e167..7e863afe 100644 --- a/test/src/test/java/jj/http/client/HttpClientIntegrationTest.java +++ b/test/src/test/java/jj/http/client/HttpClientIntegrationTest.java @@ -20,7 +20,6 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.*; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import io.netty.buffer.ByteBuf; @@ -35,6 +34,7 @@ import jj.http.client.api.RestOperation; import jj.testing.JibbrJabbrTestServer; +import jj.testing.Latch; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -64,7 +64,7 @@ public void testHttpRequester() throws Throwable { final AtomicReference response = new AtomicReference<>(); final AtomicReference cause = new AtomicReference<>(); - final CountDownLatch latch = new CountDownLatch(1); + final Latch latch = new Latch(1); requester.requestTo(server.baseUrl() + "/test2.txt") .get() diff --git a/test/src/test/java/jj/http/server/EmbeddedHttpServerTest.java b/test/src/test/java/jj/http/server/EmbeddedHttpServerTest.java index 9f7de66a..86acd02b 100644 --- a/test/src/test/java/jj/http/server/EmbeddedHttpServerTest.java +++ b/test/src/test/java/jj/http/server/EmbeddedHttpServerTest.java @@ -19,8 +19,6 @@ import static java.util.concurrent.TimeUnit.*; import static org.hamcrest.Matchers.*; -import java.util.concurrent.CountDownLatch; - import io.netty.handler.codec.http.HttpHeaderNames; import javax.inject.Inject; @@ -30,6 +28,7 @@ import jj.http.server.EmbeddedHttpServer.ResponseReady; import jj.testing.JibbrJabbrTestServer; +import jj.testing.Latch; import org.junit.Rule; import org.junit.Test; @@ -63,7 +62,7 @@ public void test() throws Throwable { @Test public void testCallback() throws Throwable { - final CountDownLatch myLatch = new CountDownLatch(3); + final Latch myLatch = new Latch(3); final AssertionError testFailures = new AssertionError("there were test failures"); ResponseReady responseReady = response -> { try { diff --git a/test/src/test/java/jj/jasmine/JasmineIntegrationTest.java b/test/src/test/java/jj/jasmine/JasmineIntegrationTest.java index 96a4ddf5..d8794efc 100644 --- a/test/src/test/java/jj/jasmine/JasmineIntegrationTest.java +++ b/test/src/test/java/jj/jasmine/JasmineIntegrationTest.java @@ -21,7 +21,6 @@ import java.nio.file.Files; import java.nio.file.attribute.FileTime; -import java.util.concurrent.CountDownLatch; import javax.inject.Inject; @@ -35,6 +34,7 @@ import jj.script.module.ScriptResource; import jj.testing.JibbrJabbrTestServer; +import jj.testing.Latch; import org.junit.Rule; import org.junit.Test; @@ -54,7 +54,7 @@ public class JasmineIntegrationTest { @Inject ResourceLoader resourceLoader; @Inject ResourceFinder resourceFinder; - CountDownLatch latch; + Latch latch; JasmineTestSuccess success; JasmineTestFailure failure; @@ -79,7 +79,7 @@ void on(JasmineTestError error) { @Test public void test() throws Exception { - latch = new CountDownLatch(2); + latch = new Latch(2); // loading a script resource triggers the jasmine run resourceLoader.loadResource(ScriptResource.class, Private, "jasmine-int-test.js"); @@ -96,7 +96,7 @@ public void test() throws Exception { // contents of test results are verified in the unit tests success = null; failure = null; - latch = new CountDownLatch(2); + latch = new Latch(2); touch(resourceFinder.findResource(ScriptResource.class, Private, "jasmine-int-test.js")); touch(resourceFinder.findResource(ScriptResource.class, Private, "jasmine-int-test-failures.js")); diff --git a/test/src/test/java/jj/repl/ReplIntegrationTest.java b/test/src/test/java/jj/repl/ReplIntegrationTest.java index 1b287267..646c3376 100644 --- a/test/src/test/java/jj/repl/ReplIntegrationTest.java +++ b/test/src/test/java/jj/repl/ReplIntegrationTest.java @@ -29,7 +29,6 @@ import io.netty.handler.codec.string.StringEncoder; import java.net.InetAddress; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; @@ -40,6 +39,7 @@ import jj.event.Subscriber; import jj.testing.JibbrJabbrTestServer; +import jj.testing.Latch; import org.junit.After; import org.junit.Rule; import org.junit.Test; @@ -57,7 +57,7 @@ public class ReplIntegrationTest { @Inject ReplConfiguration config; Bootstrap bootstrap; - CountDownLatch latch = new CountDownLatch(1); + Latch latch = new Latch(1); @Listener void on(ReplListening replListening) { @@ -77,7 +77,7 @@ public void test() throws Throwable { // well... it started so that's something // connect to config.port() and send in some commands? why not - latch = new CountDownLatch(1); + latch = new Latch(1); final AtomicReference failure = new AtomicReference<>(); diff --git a/test/src/test/java/jj/resource/ResourceSystemIntegrationTest.java b/test/src/test/java/jj/resource/ResourceSystemIntegrationTest.java index aa7225e3..7ef77340 100644 --- a/test/src/test/java/jj/resource/ResourceSystemIntegrationTest.java +++ b/test/src/test/java/jj/resource/ResourceSystemIntegrationTest.java @@ -9,7 +9,6 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.attribute.FileTime; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -30,6 +29,7 @@ import jj.script.module.ScriptResource; import jj.testing.JibbrJabbrTestServer; +import jj.testing.Latch; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -226,7 +226,7 @@ private void touch(FileResource resource) throws Exception { // also tests out the events indirectly boolean countEvents = false; - CountDownLatch latch; + Latch latch; AtomicInteger reloadedCount; AtomicInteger killedCount; AtomicInteger loadedCount; @@ -263,7 +263,7 @@ void on(ResourceLoaded event) { } private boolean waitForCount(int count) throws Exception { - latch = new CountDownLatch(count); + latch = new Latch(count); countEvents = true; return latch.await(4, SECONDS); } diff --git a/test/src/test/java/jj/script/ScriptEnvironmentIntegrationTest.java b/test/src/test/java/jj/script/ScriptEnvironmentIntegrationTest.java index 28a30b77..cf793696 100644 --- a/test/src/test/java/jj/script/ScriptEnvironmentIntegrationTest.java +++ b/test/src/test/java/jj/script/ScriptEnvironmentIntegrationTest.java @@ -22,7 +22,6 @@ import static jj.document.DocumentScriptEnvironment.*; import io.netty.handler.codec.http.HttpResponseStatus; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -43,6 +42,7 @@ import jj.script.module.RequiredModule; import jj.testing.JibbrJabbrTestServer; +import jj.testing.Latch; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -71,7 +71,7 @@ public class ScriptEnvironmentIntegrationTest { new JibbrJabbrTestServer(ServerRoot.one, App.module) .injectInstance(this); - CountDownLatch latch; + Latch latch; DocumentScriptEnvironment scriptEnvironment; @@ -93,7 +93,7 @@ void on(ScriptEnvironmentInitialized sei) { } } - private ServerTask countDown(final CountDownLatch latch) { + private ServerTask countDown(final Latch latch) { return new ServerTask("countdown") { @Override @@ -116,9 +116,9 @@ public void testingDuplicateInitializationRequestsJoin() throws Exception { // external set up documentOneCount.set(0); documentTwoCount.set(0); - latch = new CountDownLatch(2); + latch = new Latch(2); - CountDownLatch latch1 = new CountDownLatch(12); + Latch latch1 = new Latch(12); ServerTask countDown = countDown(latch1); String name1 = DOCUMENT_ONE; @@ -204,7 +204,7 @@ public void test3() throws Throwable { * @throws InterruptedException */ private void loadScriptEnvironment(final String name) throws InterruptedException { - latch = new CountDownLatch(1); + latch = new Latch(1); resourceLoader.loadResource(DocumentScriptEnvironment.class, Virtual, name); assertTrue(latch.await(1, TimeUnit.SECONDS)); } diff --git a/test/src/test/java/jj/testing/BasicServingTest.java b/test/src/test/java/jj/testing/BasicServingTest.java index ff8398bf..4e547861 100644 --- a/test/src/test/java/jj/testing/BasicServingTest.java +++ b/test/src/test/java/jj/testing/BasicServingTest.java @@ -24,7 +24,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -87,7 +86,7 @@ public class BasicServingTest { private void runBasicStressTest(final int timeout, final int totalClients, final List uris) throws Throwable { final AssertionError error = new AssertionError("failure!"); - final CountDownLatch latch = new CountDownLatch(totalClients); + final Latch latch = new Latch(totalClients); for (int i = 0; i < totalClients; ++i) { String uri = uris.get(i % uris.size()); server.request(new EmbeddedHttpRequest(uri), response -> { @@ -164,7 +163,7 @@ public void areYouKiddingMe() throws Exception { private void poundIt(final int threadCount, final int perClientTimeout, final int perClientRequestCount) throws Exception { final List requests = makeAll(); - final CountDownLatch latch = new CountDownLatch(threadCount); + final Latch latch = new Latch(threadCount); final ExecutorService service = Executors.newFixedThreadPool(threadCount); final Throwable[] throwables = new Throwable[threadCount]; diff --git a/test/src/test/java/jj/testing/SystemScriptsTest.java b/test/src/test/java/jj/testing/SystemScriptsTest.java index 40b85179..02483a64 100644 --- a/test/src/test/java/jj/testing/SystemScriptsTest.java +++ b/test/src/test/java/jj/testing/SystemScriptsTest.java @@ -26,7 +26,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; import javax.inject.Inject; @@ -63,7 +62,7 @@ private static int count(Path in) throws Exception { // the cast is ugly but if i ever end up with more than 2.1 billion // specs i guess addressing this will be a pleasure haha - return (int)Files.list(in).filter(path -> { return path.toString().endsWith(".js"); }).count(); + return (int)Files.list(in).filter(path -> path.toString().endsWith(".js")).count(); } static { @@ -98,7 +97,7 @@ private static int count(Path in) throws Exception { @Inject ResourceLoader resourceLoader; - final CountDownLatch testCountLatch = new CountDownLatch(total); + final Latch testCountLatch = new Latch(total); final AtomicInteger successCount = new AtomicInteger(); final AtomicInteger failureCount = new AtomicInteger();