diff options
author | Paul Pazderski | 2020-07-01 18:48:42 +0000 |
---|---|---|
committer | Paul Pazderski | 2020-07-01 18:48:42 +0000 |
commit | df9297cf8536bdaa582eed3649065e2323ea791e (patch) | |
tree | 06a9852fe6558287b1022dca6080f779f9e82d5c | |
parent | df0a30251c7d67951b24884e2c3cc71c4bb69b3e (diff) | |
download | eclipse.platform.debug-I20200711-1800.tar.gz eclipse.platform.debug-I20200711-1800.tar.xz eclipse.platform.debug-I20200711-1800.zip |
Bug 564849 - [Tests] Fix unstable JUnit testsY20200716-0820Y20200715-1200Y20200711-1200Y20200708-1200Y20200704-1200S4_17_0_M1I20200716-1800I20200715-1800I20200714-1800I20200713-2230I20200713-1800I20200712-1800I20200711-2250I20200711-1800I20200710-1800I20200710-0230I20200708-1800I20200708-0600I20200707-1800I20200707-0600I20200706-2300I20200706-1800I20200706-0600I20200705-1800I20200705-0710I20200705-0600I20200704-1800I20200704-0600I20200703-1800
OutputStreamMonitorTests
Two of the tests are explicit written for UTF-8 but the monitor is
initialized with default charset. Since many modern systems use UTF-8 as
default the test still works most of the times.
InputStreamMonitorTests
The closing test stops the input monitoring thread and immediately
checks if the thread is stopped. I saw a few random test failures
locally from this race condition.
BreakpointTests
Calling dispose on a view is not the right way to close the view.
Change-Id: I4e01475032dc5dd69810eedc467ba1ff3efb2ef3
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
3 files changed, 29 insertions, 15 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/breakpoint/BreakpointTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/breakpoint/BreakpointTests.java index 60a62d5b3..39c127bfb 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/breakpoint/BreakpointTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/breakpoint/BreakpointTests.java @@ -127,7 +127,7 @@ public class BreakpointTests extends AbstractDebugTest { }, this, testTimeout, c -> "Breakpoint not restored in view"); } finally { if (!viewVisible) { - view.dispose(); + DebugUIPlugin.getActiveWorkbenchWindow().getActivePage().hideView(view); } } } diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/InputStreamMonitorTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/InputStreamMonitorTests.java index b6a3b3c73..361995c89 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/InputStreamMonitorTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/InputStreamMonitorTests.java @@ -22,6 +22,7 @@ import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.nio.charset.Charset; import java.util.Set; +import java.util.function.Supplier; import org.eclipse.core.runtime.Platform; import org.eclipse.debug.internal.core.DebugCoreMessages; @@ -95,8 +96,12 @@ public class InputStreamMonitorTests extends AbstractDebugTest { @Test @SuppressWarnings("resource") public void testClose() throws Exception { - Set<Thread> allThreads = Thread.getAllStackTraces().keySet(); - long alreadyLeakedThreads = allThreads.stream().filter(t -> DebugCoreMessages.InputStreamMonitor_label.equals(t.getName())).count(); + Supplier<Long> getInputStreamMonitorThreads = () -> { + Set<Thread> allThreads = Thread.getAllStackTraces().keySet(); + long numMonitorThreads = allThreads.stream().filter(t -> DebugCoreMessages.InputStreamMonitor_label.equals(t.getName())).count(); + return numMonitorThreads; + }; + long alreadyLeakedThreads = getInputStreamMonitorThreads.get(); if (alreadyLeakedThreads > 0) { Platform.getLog(TestsPlugin.class).warn("Test started with " + alreadyLeakedThreads + " leaked monitor threads."); } @@ -130,9 +135,8 @@ public class InputStreamMonitorTests extends AbstractDebugTest { assertEquals("Stream not closed or to often.", 1, testStream.numClosed); } - allThreads = Thread.getAllStackTraces().keySet(); - long numMonitorThreads = allThreads.stream().filter(t -> DebugCoreMessages.InputStreamMonitor_label.equals(t.getName())).count(); - assertEquals("Leaked monitor threads.", 0, numMonitorThreads); + TestUtil.waitWhile(() -> getInputStreamMonitorThreads.get() > 0, 500); + assertEquals("Leaked monitor threads.", 0, (long) getInputStreamMonitorThreads.get()); } /** diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/OutputStreamMonitorTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/OutputStreamMonitorTests.java index 239aee37d..0d361021f 100644 --- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/OutputStreamMonitorTests.java +++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/OutputStreamMonitorTests.java @@ -73,7 +73,7 @@ public class OutputStreamMonitorTests extends AbstractDebugTest { @Before @SuppressWarnings("resource") public void setUp() throws IOException { - monitor = new TestOutputStreamMonitor(new PipedInputStream(sysout), null); + monitor = new TestOutputStreamMonitor(new PipedInputStream(sysout), StandardCharsets.UTF_8); } /** @@ -161,18 +161,28 @@ public class OutputStreamMonitorTests extends AbstractDebugTest { * Test that passing <code>null</code> as charset does not raise exceptions. */ @Test + @SuppressWarnings("resource") public void testNullCharset() throws Exception { String input = "o\u00F6O\u00EFiI\u00D6\u00D8\u00F8"; - monitor.addListener(fStreamListener); - monitor.startMonitoring(); - try (PrintStream out = new PrintStream(sysout)) { - out.print(input); - } - sysout.flush(); + sysout.close(); + sysout = new PipedOutputStream(); + monitor.close(); + monitor = new TestOutputStreamMonitor(new PipedInputStream(sysout), null); + try { + monitor.addListener(fStreamListener); + monitor.startMonitoring(); + try (PrintStream out = new PrintStream(sysout)) { + out.print(input); + } + sysout.flush(); - TestUtil.waitWhile(() -> notifiedChars.length() < input.length(), 500); - assertEquals("Monitor read wrong content.", input, notifiedChars.toString()); + TestUtil.waitWhile(() -> notifiedChars.length() < input.length(), 500); + assertEquals("Monitor read wrong content.", input, notifiedChars.toString()); + } finally { + sysout.close(); + monitor.close(); + } } /** |