diff --git a/syncany-daemon/src/main/java/org/syncany/operations/daemon/WatchRunner.java b/syncany-daemon/src/main/java/org/syncany/operations/daemon/WatchRunner.java index 9ccd6bb25..c30ef55d9 100644 --- a/syncany-daemon/src/main/java/org/syncany/operations/daemon/WatchRunner.java +++ b/syncany-daemon/src/main/java/org/syncany/operations/daemon/WatchRunner.java @@ -130,7 +130,7 @@ public void run() { logger.log(Level.SEVERE, "ERROR while running watch at " + config.getLocalDir(), e); } } - }, "WatchOpT/" + config.getLocalDir().getName()); + }, "WR/" + config.getLocalDir().getName()); watchThread.start(); } diff --git a/syncany-daemon/src/test/java/org/syncany/tests/daemon/BasicWatchServerTest.java b/syncany-daemon/src/test/java/org/syncany/tests/daemon/BasicWatchServerTest.java index 21386ea50..2c2e3c9fd 100644 --- a/syncany-daemon/src/test/java/org/syncany/tests/daemon/BasicWatchServerTest.java +++ b/syncany-daemon/src/test/java/org/syncany/tests/daemon/BasicWatchServerTest.java @@ -17,9 +17,7 @@ */ package org.syncany.tests.daemon; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Arrays; @@ -196,21 +194,35 @@ public void testWatchServer() throws Exception { // Create big file to trigger sync clientA.createNewFile("bigfileforlongsync", 5000); - // Wait to allow sync to start - Thread.sleep(100); - - eventBus.post(cliRequest); - - response = waitForResponse(30); + + // ^^ Now sync should start and we send 'status' requests + CliResponse cliResponse = null; + boolean syncRunningMessageReceived = false; - assertTrue(response instanceof CliResponse); - CliResponse cliResponse = (CliResponse) response; + for (i = 30; i < 50; i++) { + cliRequest.setId(i); + eventBus.post(cliRequest); + + response = waitForResponse(i); + + assertTrue(response instanceof CliResponse); + cliResponse = (CliResponse) response; + + System.out.println(cliResponse.getOutput()); + + if ("Cannot run CLI commands while sync is running or requested.\n".equals(cliResponse.getOutput())) { + syncRunningMessageReceived = true; + break; + } + + Thread.sleep(200); + } - assertEquals("Cannot run CLI commands while sync is running or requested.\n", cliResponse.getOutput()); + assertTrue(syncRunningMessageReceived); // Allow daemon to sync Thread.sleep(10000); - for (i = 31; i < 50; i++) { + for (i = 50; i < 60; i++) { cliRequest.setId(i); eventBus.post(cliRequest); @@ -224,6 +236,7 @@ public void testWatchServer() throws Exception { Thread.sleep(1000); } + assertNotNull(cliResponse); assertEquals("No local changes.\n", cliResponse.getOutput()); // Restore file test diff --git a/syncany-lib/src/main/java/org/syncany/operations/watch/WatchOperation.java b/syncany-lib/src/main/java/org/syncany/operations/watch/WatchOperation.java index 4dcfb2d40..bea8a49cb 100644 --- a/syncany-lib/src/main/java/org/syncany/operations/watch/WatchOperation.java +++ b/syncany-lib/src/main/java/org/syncany/operations/watch/WatchOperation.java @@ -235,7 +235,6 @@ private void runSync() throws Exception { syncRequested.set(false); logger.log(Level.INFO, "RUNNING SYNC ..."); - try { boolean notifyChanges = false;