Skip to content

Commit

Permalink
extending timeouts for travis
Browse files Browse the repository at this point in the history
Travis seems to want more time to do things.  Maybe.  Maybe there are
other problems too!
  • Loading branch information
Jason Miller committed Feb 26, 2016
1 parent 341139f commit 1b45bd1
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 39 deletions.
6 changes: 3 additions & 3 deletions test/src/main/java/jj/http/server/EmbeddedHttpResponse.java
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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();

Expand Down
46 changes: 46 additions & 0 deletions 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);
}
}
Expand Up @@ -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(
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
Expand Up @@ -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;
Expand All @@ -48,6 +47,7 @@
import jj.script.ScriptError;
import jj.testing.JibbrJabbrTestServer;

import jj.testing.Latch;
import org.junit.Rule;
import org.junit.Test;

Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -23,7 +23,6 @@

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.CountDownLatch;

import javax.inject.Inject;

Expand All @@ -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;
Expand All @@ -55,7 +55,7 @@ public class StylesheetResourceIntegrationTest {

StylesheetResource stylesheet;

CountDownLatch latch;
Latch latch;

@Listener
void on(ResourceLoaded event) {
Expand All @@ -68,7 +68,7 @@ void on(ResourceLoaded event) {
@Before
public void before() {
stylesheet = null;
latch = new CountDownLatch(1);
latch = new Latch(1);
}

@Test
Expand Down Expand Up @@ -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));
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -64,7 +64,7 @@ public void testHttpRequester() throws Throwable {

final AtomicReference<String> response = new AtomicReference<>();
final AtomicReference<Throwable> cause = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
final Latch latch = new Latch(1);

requester.requestTo(server.baseUrl() + "/test2.txt")
.get()
Expand Down
5 changes: 2 additions & 3 deletions test/src/test/java/jj/http/server/EmbeddedHttpServerTest.java
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions test/src/test/java/jj/jasmine/JasmineIntegrationTest.java
Expand Up @@ -21,7 +21,6 @@

import java.nio.file.Files;
import java.nio.file.attribute.FileTime;
import java.util.concurrent.CountDownLatch;

import javax.inject.Inject;

Expand All @@ -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;

Expand All @@ -54,7 +54,7 @@ public class JasmineIntegrationTest {
@Inject ResourceLoader resourceLoader;
@Inject ResourceFinder resourceFinder;

CountDownLatch latch;
Latch latch;

JasmineTestSuccess success;
JasmineTestFailure failure;
Expand All @@ -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");
Expand All @@ -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"));
Expand Down
6 changes: 3 additions & 3 deletions test/src/test/java/jj/repl/ReplIntegrationTest.java
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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<Throwable> failure = new AtomicReference<>();

Expand Down
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -71,7 +71,7 @@ public class ScriptEnvironmentIntegrationTest {
new JibbrJabbrTestServer(ServerRoot.one, App.module)
.injectInstance(this);

CountDownLatch latch;
Latch latch;

DocumentScriptEnvironment scriptEnvironment;

Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 1b45bd1

Please sign in to comment.