Skip to content

Commit b177929

Browse files
committed
Fix BanFailureLoggingTests (#75171)
Today both `BanFailureLoggingTests` fail to remove the ban and report this in the logs. `testLogsAtDebugOnDisconnectionDuringBan` does not wait for this message to be logged, so the logging might happen concurrently with the logger being stopped and removed, resulting in a `Attempted to append to non-started appender mock` failure. This commit ensures that both test cases wait for the expected removal failure message to be logged. Closes #75129
1 parent 794c2f3 commit b177929

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

server/src/test/java/org/elasticsearch/tasks/BanFailureLoggingTests.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333

3434
import java.io.Closeable;
3535
import java.util.ArrayList;
36+
import java.util.Arrays;
3637
import java.util.Collections;
38+
import java.util.List;
3739
import java.util.Map;
3840
import java.util.concurrent.atomic.AtomicInteger;
3941
import java.util.function.Function;
@@ -52,11 +54,17 @@ public void testLogsAtDebugOnDisconnectionDuringBan() throws Exception {
5254
}
5355
connection.sendRequest(requestId, action, request, options);
5456
},
55-
childNode -> new MockLogAppender.SeenEventExpectation(
56-
"cannot send message",
57-
TaskCancellationService.class.getName(),
58-
Level.DEBUG,
59-
"*cannot send ban for tasks*" + childNode.getId() + "*"));
57+
childNode -> Arrays.asList(
58+
new MockLogAppender.SeenEventExpectation(
59+
"cannot send ban",
60+
TaskCancellationService.class.getName(),
61+
Level.DEBUG,
62+
"*cannot send ban for tasks*" + childNode.getId() + "*"),
63+
new MockLogAppender.SeenEventExpectation(
64+
"cannot remove ban",
65+
TaskCancellationService.class.getName(),
66+
Level.DEBUG,
67+
"*failed to remove ban for tasks*" + childNode.getId() + "*")));
6068
}
6169

6270
@TestLogging(reason = "testing logging at DEBUG", value = "org.elasticsearch.tasks.TaskCancellationService:DEBUG")
@@ -69,16 +77,22 @@ public void testLogsAtDebugOnDisconnectionDuringBanRemoval() throws Exception {
6977
}
7078
connection.sendRequest(requestId, action, request, options);
7179
},
72-
childNode -> new MockLogAppender.SeenEventExpectation(
73-
"cannot send message",
74-
TaskCancellationService.class.getName(),
75-
Level.DEBUG,
76-
"*failed to remove ban for tasks*" + childNode.getId() + "*"));
80+
childNode -> Arrays.asList(
81+
new MockLogAppender.UnseenEventExpectation(
82+
"cannot send ban",
83+
TaskCancellationService.class.getName(),
84+
Level.DEBUG,
85+
"*cannot send ban for tasks*" + childNode.getId() + "*"),
86+
new MockLogAppender.SeenEventExpectation(
87+
"cannot remove ban",
88+
TaskCancellationService.class.getName(),
89+
Level.DEBUG,
90+
"*failed to remove ban for tasks*" + childNode.getId() + "*")));
7791
}
7892

7993
private void runTest(
8094
StubbableTransport.SendRequestBehavior sendRequestBehavior,
81-
Function<DiscoveryNode, MockLogAppender.SeenEventExpectation> expectation) throws Exception {
95+
Function<DiscoveryNode, List<MockLogAppender.LoggingExpectation>> expectations) throws Exception {
8296

8397
final ArrayList<Closeable> resources = new ArrayList<>(3);
8498

@@ -140,7 +154,9 @@ public Task createTask(long id, String type, String action, TaskId parentTaskId,
140154
Loggers.addAppender(LogManager.getLogger(TaskCancellationService.class), appender);
141155
resources.add(() -> Loggers.removeAppender(LogManager.getLogger(TaskCancellationService.class), appender));
142156

143-
appender.addExpectation(expectation.apply(childTransportService.getLocalDiscoNode()));
157+
for (MockLogAppender.LoggingExpectation expectation : expectations.apply(childTransportService.getLocalDiscoNode())) {
158+
appender.addExpectation(expectation);
159+
}
144160

145161
final PlainActionFuture<Void> cancellationFuture = new PlainActionFuture<>();
146162
parentTransportService.getTaskManager().cancelTaskAndDescendants(parentTask, "test", true, cancellationFuture);

0 commit comments

Comments
 (0)