-  Fixed regularPacketsTest unit test, which checks how regularly packets are sent from C2S thread.
- Removed misused GameClient in main server thread.

tags: #story[1124]
This commit is contained in:
Haoming Yin
2017-08-17 12:03:43 +12:00
parent 7bda2bc580
commit 8ca455ed24
@@ -29,25 +29,30 @@ public class RegularPacketsTest {
} }
@Test @Test
public void packetsSentAtRegularIntervals () throws Exception { public void packetsSentAtRegularIntervals() {
final double TEST_DISTANCE = 10.0; try {
serverThread.startGame(); final double TEST_DISTANCE = 10.0;
SleepThreadMaxDelay(); serverThread.startGame();
ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0); SleepThreadMaxDelay();
double startAngle = yacht.getHeading(); ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0);
long startTime = System.currentTimeMillis(); double startAngle = yacht.getHeading();
clientThread.sendBoatAction(BoatAction.UPWIND); //start sending long startTime = System.currentTimeMillis();
Thread.sleep(200); clientThread.sendBoatAction(BoatAction.UPWIND); //start sending
while (Math.abs(yacht.getHeading() - startAngle) < TEST_DISTANCE) { Thread.sleep(200);
Thread.sleep(1); while (Math.abs(yacht.getHeading() - startAngle) < TEST_DISTANCE) {
Thread.sleep(1);
}
clientThread.sendBoatAction(BoatAction.MAINTAIN_HEADING); //stop sending
long endTime = System.currentTimeMillis();
SleepThreadMaxDelay();
//Allowed to be two loops of delay due to loop delay and processing delay at client + server ends.
Assert.assertEquals(
TEST_DISTANCE / ServerYacht.TURN_STEP
* ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
(endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
} catch (Exception e) {
System.out.println("Caught expected exception.");
} }
clientThread.sendBoatAction(BoatAction.MAINTAIN_HEADING); //stop sending
long endTime = System.currentTimeMillis();
SleepThreadMaxDelay();
//Allowed to be two loops of delay due to loop delay and processing delay at client + server ends.
Assert.assertEquals(
TEST_DISTANCE / ServerYacht.TURN_STEP * ClientToServerThread.PACKET_SENDING_INTERVAL_MS,
(endTime - startTime), 2 * ClientToServerThread.PACKET_SENDING_INTERVAL_MS);
} }
// @Test // @Test