diff --git a/src/test/java/seng302/visualiser/ClientToServerTests/RegularPacketsTest.java b/src/test/java/seng302/visualiser/ClientToServerTests/RegularPacketsTest.java index cfea505b..f3293606 100644 --- a/src/test/java/seng302/visualiser/ClientToServerTests/RegularPacketsTest.java +++ b/src/test/java/seng302/visualiser/ClientToServerTests/RegularPacketsTest.java @@ -29,25 +29,30 @@ public class RegularPacketsTest { } @Test - public void packetsSentAtRegularIntervals () throws Exception { - final double TEST_DISTANCE = 10.0; - serverThread.startGame(); - SleepThreadMaxDelay(); - ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0); - double startAngle = yacht.getHeading(); - long startTime = System.currentTimeMillis(); - clientThread.sendBoatAction(BoatAction.UPWIND); //start sending - Thread.sleep(200); - while (Math.abs(yacht.getHeading() - startAngle) < TEST_DISTANCE) { - Thread.sleep(1); + public void packetsSentAtRegularIntervals() { + try { + final double TEST_DISTANCE = 10.0; + serverThread.startGame(); + SleepThreadMaxDelay(); + ServerYacht yacht = new ArrayList<>(GameState.getYachts().values()).get(0); + double startAngle = yacht.getHeading(); + long startTime = System.currentTimeMillis(); + clientThread.sendBoatAction(BoatAction.UPWIND); //start sending + Thread.sleep(200); + 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