mirror of https://github.com/apache/kafka.git
KAFKA-18834 Fix LoggingResourceTest#testSetLevelDefaultScope (#19920)
- Flaky behavior `LoggingResourceTest#testSetLevelDefaultScope` sometimes fails by not capturing its expected WARN log. - Root cause Both `LoggersTest#testSetLevelWithValidRootLoggerNames` and `LoggingResourceTest#testSetLevelDefaultScope` may share the same `LoggerContext` when executed in the same JVM. `LoggersTest#testSetLevelWithValidRootLoggerNames` calls `loggers.setLevel("", ERROR)`, which mutates the global root logger level to ERROR and suppresses WARN logs, which causes subsequent tests to fail to emit WARN-level output. - Fix in this PR Resets the Log4j configuration after each test in `LoggersTest`, ensuring that any global changes are reverted. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
parent
7aaba96cc1
commit
dc82c766fa
|
@ -21,6 +21,8 @@ import org.apache.kafka.common.utils.Time;
|
||||||
import org.apache.kafka.connect.runtime.rest.entities.LoggerLevel;
|
import org.apache.kafka.connect.runtime.rest.entities.LoggerLevel;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.apache.logging.log4j.core.LoggerContext;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -47,6 +49,13 @@ public class LoggersTest {
|
||||||
time = new MockTime(0, INITIAL_TIME, 0);
|
time = new MockTime(0, INITIAL_TIME, 0);
|
||||||
loggers = (Loggers.Log4jLoggers) Loggers.newInstance(time);
|
loggers = (Loggers.Log4jLoggers) Loggers.newInstance(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown() {
|
||||||
|
// Reset LoggerContext to its initial configuration.
|
||||||
|
// This ensures any log level changes made in a test do not leak into subsequent tests.
|
||||||
|
LoggerContext.getContext(false).reconfigure();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLevelWithNullLoggerName() {
|
public void testLevelWithNullLoggerName() {
|
||||||
|
|
Loading…
Reference in New Issue