Skip to content

Commit

Permalink
Ensure JULBridgeTests resets root logging level after test
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed Oct 6, 2023
1 parent 571d4a4 commit ea4f34b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ if (BuildParams.isSnapshotBuild() == false) {

tasks.named("test").configure {
systemProperty 'es.insecure_network_trace_enabled', 'true'
maxParallelForks = 1
}

tasks.named("thirdPartyAudit").configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
import org.junit.BeforeClass;

import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.instanceOf;

public class JULBridgeTests extends ESTestCase {

private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger("");
private static java.util.logging.Level savedLevel;
private static java.util.logging.Handler[] savedHandlers;
private static Handler[] savedHandlers;

@BeforeClass
public static void saveLoggerState() {
Expand Down Expand Up @@ -60,17 +60,20 @@ public static void restoreLoggerState() {

private void assertLogged(Runnable loggingCode, LoggingExpectation... expectations) {
Logger testLogger = LogManager.getLogger("");
Loggers.setLevel(testLogger, Level.ALL);
Level savedLevel = testLogger.getLevel();
MockLogAppender mockAppender = new MockLogAppender();
mockAppender.start();

try {
Loggers.setLevel(testLogger, Level.ALL);
mockAppender.start();
Loggers.addAppender(testLogger, mockAppender);
for (var expectation : expectations) {
mockAppender.addExpectation(expectation);
}
loggingCode.run();
mockAppender.assertAllExpectationsMatched();
} finally {
Loggers.setLevel(testLogger, savedLevel);
Loggers.removeAppender(testLogger, mockAppender);
mockAppender.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.SetOnce;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.ActionListener;
Expand Down Expand Up @@ -228,7 +227,6 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.Mockito.mock;

@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/100434")
public class SnapshotResiliencyTests extends ESTestCase {

private DeterministicTaskQueue deterministicTaskQueue;
Expand Down

0 comments on commit ea4f34b

Please sign in to comment.