race conditions are the best bugs
This commit is contained in:
parent
efae2d0509
commit
4d79b34b31
|
@ -1,6 +1,9 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import com.rusefi.proxy.BaseBroadcastingThread;
|
||||
import com.rusefi.server.ControllerInfo;
|
||||
import com.rusefi.server.SessionDetails;
|
||||
|
@ -32,7 +35,18 @@ public class MockRusEfiDevice {
|
|||
Socket socket = rusEFISSLContext.getSSLSocket(LOCALHOST, serverPort);
|
||||
BaseBroadcastingThread baseBroadcastingThread = new BaseBroadcastingThread(socket,
|
||||
sessionDetails,
|
||||
logger);
|
||||
logger) {
|
||||
@Override
|
||||
protected void handleCommand(BinaryProtocolServer.Packet packet, TcpIoStream stream) throws IOException {
|
||||
super.handleCommand(packet, stream);
|
||||
|
||||
if (packet.getPacket()[0] == Fields.TS_OUTPUT_COMMAND) {
|
||||
byte[] response = new byte[1 + Fields.TS_OUTPUT_SIZE];
|
||||
response[0] = (byte) BinaryProtocolServer.TS_OK.charAt(0);
|
||||
stream.sendPacket(response, logger);
|
||||
}
|
||||
}
|
||||
};
|
||||
baseBroadcastingThread.start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,11 +50,20 @@ public class ServerTest {
|
|||
CountDownLatch allClientsDisconnected = new CountDownLatch(1);
|
||||
CountDownLatch onConnected = new CountDownLatch(2);
|
||||
|
||||
CountDownLatch allConnected = new CountDownLatch(1);
|
||||
|
||||
|
||||
try (Backend backend = new Backend(userDetailsResolver, httpPort, logger) {
|
||||
@Override
|
||||
public void register(ControllerConnectionState clientConnectionState) {
|
||||
super.register(clientConnectionState);
|
||||
onConnected.countDown();
|
||||
try {
|
||||
allConnected.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,6 +90,8 @@ public class ServerTest {
|
|||
List<UserDetails> onlineUsers = ProxyClient.getOnlineUsers(httpPort);
|
||||
assertEquals(2, onlineUsers.size());
|
||||
|
||||
allConnected.countDown();
|
||||
|
||||
assertTrue("allClientsDisconnected", allClientsDisconnected.await(30, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,11 +159,11 @@ public class Backend implements Closeable {
|
|||
try {
|
||||
controllerConnectionState.requestControllerInfo();
|
||||
|
||||
|
||||
// IMPORTANT: has to happen before we register controller while we still have exclusive access
|
||||
controllerConnectionState.getOutputs();
|
||||
|
||||
register(controllerConnectionState);
|
||||
} catch (IOException e) {
|
||||
} catch (Throwable e) {
|
||||
close(controllerConnectionState);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue