Ticket #16010: v2-0023-JOSMTestRules-synchronize-worker-thread-after-tes.patch

File v2-0023-JOSMTestRules-synchronize-worker-thread-after-tes.patch, 2.1 KB (added by ris, 15 months ago)
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    From 3b881ade562539697a4d278f0bb03b7185a76b42 Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Sat, 12 May 2018 11:22:10 +0100
    Subject: [PATCH v2 23/28] JOSMTestRules: synchronize worker thread after tests
    
    ---
     .../org/openstreetmap/josm/testutils/JOSMTestRules.java     | 13 ++++++++-----
     1 file changed, 8 insertions(+), 5 deletions(-)
    
    diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
    index b24fc3939..ee2e3471d 100644
    a b import org.openstreetmap.josm.tools.RightAndLefthandTraffic; 
    5050import org.openstreetmap.josm.tools.Territories;
    5151import org.openstreetmap.josm.tools.date.DateUtils;
    5252
     53import org.awaitility.Awaitility;
     54
    5355import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    5456
    5557/**
    public class JOSMTestRules implements TestRule { 
    573575    @SuppressFBWarnings("DM_GC")
    574576    protected void after() throws ReflectiveOperationException {
    575577        // Sync AWT Thread
    576         GuiHelper.runInEDTAndWait(new Runnable() {
    577             @Override
    578             public void run() {
    579             }
    580         });
     578        GuiHelper.runInEDTAndWait(() -> { });
     579        // Sync worker thread
     580        final boolean[] queueEmpty = {false};
     581        MainApplication.worker.submit(() -> queueEmpty[0] = true);
     582        Awaitility.await().forever().until(() -> queueEmpty[0]);
    581583        // Remove all layers
    582584        cleanLayerEnvironment();
    583585        MemoryManagerTest.resetState(allowMemoryManagerLeaks);
    public class JOSMTestRules implements TestRule { 
    658660                if (exception != null) {
    659661                    throw exception;
    660662                } else {
     663                    Logging.debug("Thread state at timeout: {0}", Thread.getAllStackTraces());
    661664                    throw new Exception(MessageFormat.format("Test timed out after {0}ms", timeout));
    662665                }
    663666            }