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;
|
| 50 | 50 | import org.openstreetmap.josm.tools.Territories; |
| 51 | 51 | import org.openstreetmap.josm.tools.date.DateUtils; |
| 52 | 52 | |
| | 53 | import org.awaitility.Awaitility; |
| | 54 | |
| 53 | 55 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 54 | 56 | |
| 55 | 57 | /** |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 573 | 575 | @SuppressFBWarnings("DM_GC") |
| 574 | 576 | protected void after() throws ReflectiveOperationException { |
| 575 | 577 | // 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]); |
| 581 | 583 | // Remove all layers |
| 582 | 584 | cleanLayerEnvironment(); |
| 583 | 585 | MemoryManagerTest.resetState(allowMemoryManagerLeaks); |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 658 | 660 | if (exception != null) { |
| 659 | 661 | throw exception; |
| 660 | 662 | } else { |
| | 663 | Logging.debug("Thread state at timeout: {0}", Thread.getAllStackTraces()); |
| 661 | 664 | throw new Exception(MessageFormat.format("Test timed out after {0}ms", timeout)); |
| 662 | 665 | } |
| 663 | 666 | } |