Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2020-07-01 18:48:42 +0000
committerPaul Pazderski2020-07-01 18:48:42 +0000
commitdf9297cf8536bdaa582eed3649065e2323ea791e (patch)
tree06a9852fe6558287b1022dca6080f779f9e82d5c
parentdf0a30251c7d67951b24884e2c3cc71c4bb69b3e (diff)
downloadeclipse.platform.debug-df9297cf8536bdaa582eed3649065e2323ea791e.tar.gz
eclipse.platform.debug-df9297cf8536bdaa582eed3649065e2323ea791e.tar.xz
eclipse.platform.debug-df9297cf8536bdaa582eed3649065e2323ea791e.zip
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>
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/breakpoint/BreakpointTests.java2
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/InputStreamMonitorTests.java14
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/OutputStreamMonitorTests.java28
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();
+ }
}
/**

Back to the top