diff --git a/java_console/ui/src/test/java/com/rusefi/FullServerTest.java b/java_console/ui/src/test/java/com/rusefi/FullServerTest.java index 5b96939a47..8af2ccf4e2 100644 --- a/java_console/ui/src/test/java/com/rusefi/FullServerTest.java +++ b/java_console/ui/src/test/java/com/rusefi/FullServerTest.java @@ -55,16 +55,8 @@ public class FullServerTest { // first start backend server - CountDownLatch controllerServerCreated = new CountDownLatch(1); - CountDownLatch applicationServerCreated = new CountDownLatch(1); - - backend.runControllerConnector(serverPortForControllers, parameter -> controllerServerCreated.countDown()); - - backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown()); - - assertTrue(controllerServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); - assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); - + TestHelper.runControllerConnectorBlocking(backend, serverPortForControllers); + TestHelper.runApplicationConnectorBlocking(backend, serverPortForRemoteUsers); // create virtual controller to which "rusEFI network connector" connects to int controllerPort = 7002; diff --git a/java_console/ui/src/test/java/com/rusefi/ServerTest.java b/java_console/ui/src/test/java/com/rusefi/ServerTest.java index 55cf5af470..230484f3ec 100644 --- a/java_console/ui/src/test/java/com/rusefi/ServerTest.java +++ b/java_console/ui/src/test/java/com/rusefi/ServerTest.java @@ -8,6 +8,7 @@ import com.rusefi.server.*; import com.rusefi.tools.online.HttpUtil; import com.rusefi.tools.online.ProxyClient; import com.rusefi.tools.online.PublicSession; +import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; @@ -17,7 +18,6 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import static com.rusefi.Timeouts.READ_IMAGE_TIMEOUT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -42,10 +42,9 @@ public class ServerTest { } @Test - public void testControllerSessionTimeout() throws InterruptedException, IOException { + public void testControllerSessionStartupTimeTimeout() throws InterruptedException, IOException { int serverPortForControllers = 7000; int httpPort = 8000; - UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6)); CountDownLatch serverCreated = new CountDownLatch(1); CountDownLatch allClientsDisconnected = new CountDownLatch(1); @@ -54,7 +53,7 @@ public class ServerTest { CountDownLatch allConnected = new CountDownLatch(1); - try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) { + try (Backend backend = new Backend(createTestUserResolver(), httpPort, logger) { @Override public void register(ControllerConnectionState clientConnectionState) { super.register(clientConnectionState); @@ -97,13 +96,27 @@ public class ServerTest { } } + @Test + public void testApplicationTimeout() throws InterruptedException { + int serverPortForRemoteUsers = 6999; + int serverPortForControllers = 6997; + int httpPort = 6998; + + try (Backend backend = new Backend(createTestUserResolver(), httpPort, logger)) { + + TestHelper.runApplicationConnectorBlocking(backend, serverPortForRemoteUsers); + + TestHelper.runControllerConnectorBlocking(backend, serverPortForControllers); + + } + } + @Test public void testInvalidApplicationRequest() throws InterruptedException, IOException { - UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6)); int httpPort = 8001; int serverPortForRemoteUsers = 6801; CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1); - try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) { + try (Backend backend = new Backend(createTestUserResolver(), httpPort, logger) { @Override protected void onDisconnectApplication() { super.onDisconnectApplication(); @@ -111,9 +124,7 @@ public class ServerTest { } }) { - CountDownLatch applicationServerCreated = new CountDownLatch(1); - backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown()); - assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + TestHelper.runApplicationConnectorBlocking(backend, serverPortForRemoteUsers); // start authenticator IoStream authenticatorToProxyStream = TestHelper.secureConnectToLocalhost(serverPortForRemoteUsers, logger); @@ -123,16 +134,20 @@ public class ServerTest { } } + @NotNull + private static UserDetailsResolver createTestUserResolver() { + return authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6)); + } + @Test public void testAuthenticatorRequestUnknownSession() throws InterruptedException, IOException { int serverPortForRemoteUsers = 6800; - UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6)); int httpPort = 8002; CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1); - try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) { + try (Backend backend = new Backend(createTestUserResolver(), httpPort, logger) { @Override protected void onDisconnectApplication() { super.onDisconnectApplication(); @@ -140,9 +155,7 @@ public class ServerTest { } }) { - CountDownLatch applicationServerCreated = new CountDownLatch(1); - backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown()); - assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + TestHelper.runApplicationConnectorBlocking(backend, serverPortForRemoteUsers); SessionDetails sessionDetails = MockRusEfiDevice.createTestSession(MockRusEfiDevice.TEST_TOKEN_1, Fields.TS_SIGNATURE); ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, 123); diff --git a/java_console/ui/src/test/java/com/rusefi/TestHelper.java b/java_console/ui/src/test/java/com/rusefi/TestHelper.java index e533516dc7..d506278df4 100644 --- a/java_console/ui/src/test/java/com/rusefi/TestHelper.java +++ b/java_console/ui/src/test/java/com/rusefi/TestHelper.java @@ -11,6 +11,7 @@ import com.rusefi.io.LinkConnector; import com.rusefi.io.LinkManager; import com.rusefi.io.tcp.BinaryProtocolServer; import com.rusefi.io.tcp.TcpIoStream; +import com.rusefi.server.Backend; import com.rusefi.server.rusEFISSLContext; import com.rusefi.tune.xml.Constant; import org.jetbrains.annotations.NotNull; @@ -80,4 +81,16 @@ public class TestHelper { assertTrue(controllerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); return server; } + + public static void runApplicationConnectorBlocking(Backend backend, int serverPortForRemoteUsers) throws InterruptedException { + CountDownLatch applicationServerCreated = new CountDownLatch(1); + backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown()); + assertTrue(applicationServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + } + + public static void runControllerConnectorBlocking(Backend backend, int serverPortForControllers) throws InterruptedException { + CountDownLatch controllerServerCreated = new CountDownLatch(1); + backend.runControllerConnector(serverPortForControllers, parameter -> controllerServerCreated.countDown()); + assertTrue(controllerServerCreated.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS)); + } }