time for more tests
This commit is contained in:
parent
8e607dd243
commit
bade31ef40
|
@ -63,7 +63,7 @@ public class LocalApplicationProxy implements Closeable {
|
|||
THREAD_FACTORY.newThread(() -> {
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
while (relayCommandCounter.get() < 4) {
|
||||
while (relayCommandCounter.get() < 4 && !isTimeForApplicationToConnect(context, start)) {
|
||||
sleep(context.gaugePokingPeriod());
|
||||
byte[] commandPacket = GetOutputsCommand.createRequest();
|
||||
|
||||
|
@ -73,6 +73,12 @@ public class LocalApplicationProxy implements Closeable {
|
|||
authenticatorToProxyStream.readPacket();
|
||||
}
|
||||
}
|
||||
|
||||
if (isTimeForApplicationToConnect(context, start) && relayCommandCounter.get() < 4) {
|
||||
// we should not keep controller blocker, time to auto-disconnect
|
||||
authenticatorToProxyStream.close();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("Gauge poker", e);
|
||||
}
|
||||
|
@ -85,6 +91,10 @@ public class LocalApplicationProxy implements Closeable {
|
|||
return serverHolder;
|
||||
}
|
||||
|
||||
private static boolean isTimeForApplicationToConnect(LocalApplicationProxyContext context, long start) {
|
||||
return System.currentTimeMillis() - start > context.startUpIdle();
|
||||
}
|
||||
|
||||
public static void sendHello(IoStream authenticatorToProxyStream, ApplicationRequest applicationRequest) throws IOException {
|
||||
log.info("Pushing " + applicationRequest);
|
||||
// right from connection push session authentication data
|
||||
|
|
|
@ -54,7 +54,7 @@ public class LocalApplicationProxyTest {
|
|||
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, createTestUserResolver().apply(TEST_TOKEN_1));
|
||||
|
||||
CountDownLatch disconnected = new CountDownLatch(1);
|
||||
LocalApplicationProxy.startAndRun(context, applicationRequest, -1, () -> disconnected.countDown(), LocalApplicationProxy.ConnectionListener.VOID);
|
||||
LocalApplicationProxy.startAndRun(context, applicationRequest, -1, disconnected::countDown, LocalApplicationProxy.ConnectionListener.VOID);
|
||||
|
||||
assertTrue(disconnected.await(30, TimeUnit.SECONDS));
|
||||
mockBackend.close();
|
||||
|
@ -73,7 +73,7 @@ public class LocalApplicationProxyTest {
|
|||
|
||||
HelloCommand.getHelloResponse(applicationClientStream.getDataBuffer());
|
||||
|
||||
while (gaugePokes.getCount() > 0) {
|
||||
while (!socket.isClosed()) {
|
||||
BinaryProtocolServer.Packet packet = applicationClientStream.readPacket();
|
||||
System.out.println("Got packet " + findCommand(packet.getPacket()[0]));
|
||||
|
||||
|
@ -94,14 +94,14 @@ public class LocalApplicationProxyTest {
|
|||
SessionDetails sessionDetails = TestHelper.createTestSession(TEST_TOKEN_1, Fields.TS_SIGNATURE);
|
||||
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, createTestUserResolver().apply(TEST_TOKEN_1));
|
||||
|
||||
LocalApplicationProxy.startAndRun(context, applicationRequest, -1, TcpIoStream.DisconnectListener.VOID, LocalApplicationProxy.ConnectionListener.VOID);
|
||||
CountDownLatch disconnected = new CountDownLatch(1);
|
||||
LocalApplicationProxy.startAndRun(context, applicationRequest, -1, disconnected::countDown, LocalApplicationProxy.ConnectionListener.VOID);
|
||||
|
||||
// wait for three output requests to take place
|
||||
assertTrue(gaugePokes.await(30, TimeUnit.SECONDS));
|
||||
|
||||
|
||||
|
||||
assertTrue("gaugePokes", gaugePokes.await(30, TimeUnit.SECONDS));
|
||||
|
||||
// but there must be a disconnect after some time
|
||||
assertTrue("disconnected", disconnected.await(30, TimeUnit.SECONDS));
|
||||
|
||||
mockBackend.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue