diff --git a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImplTest.java b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImplTest.java index a3a26c3400..3e9aa2e491 100644 --- a/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImplTest.java +++ b/services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/swap/job/SwapJobImplTest.java @@ -83,13 +83,17 @@ public class SwapJobImplTest { } } + private void waitASecond() { + try { Thread.sleep(1 * 1000); } catch (Exception _e) {} + } + @Test public void startingTimerAlwaysCausesASwap() { swapJob.lowWatermarkBytes = 16384; swapJob.interval = Duration.ofHours(1); assertEquals(0, swapJob.swaps.get()); swapJob.start(); - while (swapJob.swaps.get() <= 0); + do { waitASecond(); } while (swapJob.swaps.get() <= 0); assertTrue(swapJob.swaps.get() > 0); } @@ -98,7 +102,7 @@ public class SwapJobImplTest { swapJob.lowWatermarkBytes = 16384; assertEquals(0, swapJob.swaps.get()); swapJob.start(); - while (swapJob.swaps.get() <= 1); + do { waitASecond(); } while (swapJob.swaps.get() <= 1); assertTrue(swapJob.swaps.get() > 1); } @@ -107,7 +111,7 @@ public class SwapJobImplTest { swapJob.highWatermarkBytes = 65536; assertEquals(2, dbStore.getNumUnswappedProjects()); swapJob.start(); - while (swapJob.swaps.get() < 1); + do { waitASecond(); } while (swapJob.swaps.get() < 1); assertEquals(2, dbStore.getNumUnswappedProjects()); } @@ -118,14 +122,14 @@ public class SwapJobImplTest { assertEquals(2, dbStore.getNumUnswappedProjects()); assertEquals("proj2", dbStore.getOldestUnswappedProject()); swapJob.start(); - while (swapJob.swaps.get() < 1); + do { waitASecond(); } while (swapJob.swaps.get() < 1); assertEquals(1, dbStore.getNumUnswappedProjects()); assertEquals("proj1", dbStore.getOldestUnswappedProject()); assertEquals("bzip2", dbStore.getSwapCompression("proj2")); swapJob.restore("proj2"); assertEquals(null, dbStore.getSwapCompression("proj2")); int numSwaps = swapJob.swaps.get(); - while (swapJob.swaps.get() <= numSwaps); + do { waitASecond(); } while (swapJob.swaps.get() <= numSwaps); assertEquals(1, dbStore.getNumUnswappedProjects()); assertEquals("proj2", dbStore.getOldestUnswappedProject()); } @@ -147,14 +151,14 @@ public class SwapJobImplTest { assertEquals(2, dbStore.getNumUnswappedProjects()); assertEquals("proj2", dbStore.getOldestUnswappedProject()); swapJob.start(); - while (swapJob.swaps.get() < 1); + do { waitASecond(); } while (swapJob.swaps.get() < 1); assertEquals(1, dbStore.getNumUnswappedProjects()); assertEquals("proj1", dbStore.getOldestUnswappedProject()); assertEquals("gzip", dbStore.getSwapCompression("proj2")); swapJob.restore("proj2"); assertEquals(null, dbStore.getSwapCompression("proj2")); int numSwaps = swapJob.swaps.get(); - while (swapJob.swaps.get() <= numSwaps); + do { waitASecond(); } while (swapJob.swaps.get() <= numSwaps); assertEquals(1, dbStore.getNumUnswappedProjects()); assertEquals("proj2", dbStore.getOldestUnswappedProject()); }