Increased timeouts for tests that connect to external sites.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2019-04-16 11:43:49 +02:00
parent 64549fb19c
commit 267991982e
3 changed files with 60 additions and 43 deletions

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.alpn.java.client;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.Security;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -39,6 +40,7 @@ import org.eclipse.jetty.util.FuturePromise;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@ -50,6 +52,11 @@ public class ConscryptHTTP2ClientTest
@Test
public void testConscryptHTTP2Client() throws Exception
{
String host = "webtide.com";
int port = 443;
Assumptions.assumeTrue(canConnectTo(host, port));
Security.insertProviderAt(new OpenSSLProvider(), 1);
SslContextFactory sslContextFactory = new SslContextFactory.Client();
sslContextFactory.setProvider("Conscrypt");
@ -61,9 +68,6 @@ public class ConscryptHTTP2ClientTest
client.addBean(sslContextFactory);
client.start();
String host = "webtide.com";
int port = 443;
FuturePromise<Session> sessionPromise = new FuturePromise<>();
client.connect(sslContextFactory, new InetSocketAddress(host, port), new Session.Listener.Adapter(), sessionPromise);
Session session = sessionPromise.get(5, TimeUnit.SECONDS);
@ -93,11 +97,24 @@ public class ConscryptHTTP2ClientTest
}
});
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(latch.await(15, TimeUnit.SECONDS));
}
finally
{
client.stop();
}
}
private boolean canConnectTo(String host, int port)
{
try
{
new Socket(host, port).close();
return true;
}
catch (Throwable x)
{
return false;
}
}
}

View File

@ -19,6 +19,7 @@
package org.eclipse.jetty.alpn.java.client;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -36,6 +37,7 @@ import org.eclipse.jetty.util.FuturePromise;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@ -45,17 +47,18 @@ public class JDK9HTTP2ClientTest
@Test
public void testJDK9HTTP2Client() throws Exception
{
SslContextFactory sslContextFactory = new SslContextFactory.Client();
String host = "webtide.com";
int port = 443;
Assumptions.assumeTrue(canConnectTo(host, port));
HTTP2Client client = new HTTP2Client();
try
{
SslContextFactory sslContextFactory = new SslContextFactory.Client();
client.addBean(sslContextFactory);
client.start();
String host = "webtide.com";
int port = 443;
FuturePromise<Session> sessionPromise = new FuturePromise<>();
client.connect(sslContextFactory, new InetSocketAddress(host, port), new Session.Listener.Adapter(), sessionPromise);
Session session = sessionPromise.get(5, TimeUnit.SECONDS);
@ -85,11 +88,24 @@ public class JDK9HTTP2ClientTest
}
});
latch.await(5, TimeUnit.SECONDS);
latch.await(15, TimeUnit.SECONDS);
}
finally
{
client.stop();
}
}
private boolean canConnectTo(String host, int port)
{
try
{
new Socket(host, port).close();
return true;
}
catch (Throwable x)
{
return false;
}
}
}

View File

@ -66,30 +66,23 @@ public class ExternalSiteTest
assumeCanConnectTo(host, port);
final CountDownLatch latch1 = new CountDownLatch(1);
client.newRequest(host, port).send(new Response.CompleteListener()
client.newRequest(host, port).send(result ->
{
@Override
public void onComplete(Result result)
{
if (!result.isFailed() && result.getResponse().getStatus() == 200)
latch1.countDown();
}
assertTrue(result.isSucceeded());
assertEquals(200, result.getResponse().getStatus());
latch1.countDown();
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertTrue(latch1.await(15, TimeUnit.SECONDS));
// Try again the same URI, but without specifying the port
final CountDownLatch latch2 = new CountDownLatch(1);
client.newRequest("http://" + host).send(new Response.CompleteListener()
client.newRequest("http://" + host).send(result ->
{
@Override
public void onComplete(Result result)
{
assertTrue(result.isSucceeded());
assertEquals(200, result.getResponse().getStatus());
latch2.countDown();
}
assertTrue(result.isSucceeded());
assertEquals(200, result.getResponse().getStatus());
latch2.countDown();
});
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertTrue(latch2.await(15, TimeUnit.SECONDS));
}
@Tag("external")
@ -107,16 +100,13 @@ public class ExternalSiteTest
assumeCanConnectTo(host, port);
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest(host, port).scheme("https").path("/nvp").send(new Response.CompleteListener()
client.newRequest(host, port).scheme("https").path("/nvp").send(result ->
{
@Override
public void onComplete(Result result)
{
if (result.isSucceeded() && result.getResponse().getStatus() == 200)
latch.countDown();
}
assertTrue(result.isSucceeded());
assertEquals(200, result.getResponse().getStatus());
latch.countDown();
});
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(latch.await(15, TimeUnit.SECONDS));
}
@Tag("external")
@ -133,14 +123,7 @@ public class ExternalSiteTest
{
final CountDownLatch latch = new CountDownLatch(3);
client.newRequest(host, port)
.onResponseFailure(new Response.FailureListener()
{
@Override
public void onFailure(Response response, Throwable failure)
{
latch.countDown();
}
})
.onResponseFailure((response, failure) -> latch.countDown())
.send(new Response.Listener.Adapter()
{
@Override
@ -156,7 +139,7 @@ public class ExternalSiteTest
latch.countDown();
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertTrue(latch.await(15, TimeUnit.SECONDS));
}
}
@ -173,6 +156,7 @@ public class ExternalSiteTest
ContentResponse response = client.newRequest(host, port)
.scheme(HttpScheme.HTTPS.asString())
.path("/twitter")
.timeout(15, TimeUnit.SECONDS)
.send();
assertEquals(200, response.getStatus());
}