Skip to content

Commit

Permalink
Log actual errors instead of only number in ProcessConsoleTests eclip…
Browse files Browse the repository at this point in the history
…se-platform#1033

The ProcessConsoleTests are randomly failing because some error is
logged during test execution. The error message does, however, only
contain the number of logged errors, but not the error itself. With this
change, actual errors are stored and output rather than only their
number.

Contributes to
eclipse-platform#1033
  • Loading branch information
HeikoKlare committed Dec 18, 2023
1 parent 641757e commit 4b9ad9c
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.debug.tests.console;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
Expand All @@ -32,12 +33,13 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.function.Predicate;

import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
Expand Down Expand Up @@ -74,15 +76,15 @@
*/
public class ProcessConsoleTests extends AbstractDebugTest {
/**
* Number of received log messages with severity error while running a
* single test method.
* Log messages with severity error received while running a single test
* method.
*/
private final AtomicInteger loggedErrors = new AtomicInteger(0);
private final List<IStatus> loggedErrors = Collections.synchronizedList(new ArrayList<>());

/** Listener to count error messages in {@link ConsolePlugin} log. */
private final ILogListener errorLogListener = (status, plugin) -> {
if (status.matches(IStatus.ERROR)) {
loggedErrors.incrementAndGet();
loggedErrors.add(status);
}
};

Expand All @@ -93,7 +95,7 @@ public class ProcessConsoleTests extends AbstractDebugTest {
@Before
public void setUp() throws Exception {
super.setUp();
loggedErrors.set(0);
loggedErrors.clear();
Platform.addLogListener(errorLogListener);
}

Expand All @@ -108,7 +110,7 @@ public void tearDown() throws Exception {

super.tearDown();

assertEquals("Test triggered errors.", 0, loggedErrors.get());
assertThat("Test triggered errors.", loggedErrors, empty());
}

/**
Expand Down

0 comments on commit 4b9ad9c

Please sign in to comment.