Skip to content

Commit 0a6ef1c

Browse files
authored
Reinstate testLogsWarningPeriodicallyIfClusterNotFormed (#95416)
This test now works for atomic-register coordinators, with slightly different assertions about the log messages. Relates #95409
1 parent 05e33f6 commit 0a6ef1c

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

server/src/test/java/org/elasticsearch/cluster/coordination/AtomicRegisterCoordinatorTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ public void testUnhealthyLeaderIsReplaced() {
6565
}
6666

6767
@Override
68-
@AwaitsFix(bugUrl = "ES-5645")
68+
@TestLogging(
69+
reason = "testing ClusterFormationFailureHelper logging",
70+
value = "org.elasticsearch.cluster.coordination.ClusterFormationFailureHelper:WARN"
71+
)
6972
public void testLogsWarningPeriodicallyIfClusterNotFormed() {
70-
// All nodes have access to the register, therefore it's possible to form a single-node cluster
73+
testLogsWarningPeriodicallyIfClusterNotFormed(
74+
"master not discovered or elected yet, an election requires a node with id [",
75+
nodeId -> "*have discovered possible quorum *" + nodeId + "*discovery will continue*"
76+
);
7177
}
7278

7379
@Override

server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.util.concurrent.atomic.AtomicBoolean;
5555
import java.util.concurrent.atomic.AtomicReference;
5656
import java.util.function.Function;
57+
import java.util.function.UnaryOperator;
5758
import java.util.stream.Collectors;
5859

5960
import static java.util.Collections.emptyMap;
@@ -1602,6 +1603,13 @@ public void testClusterRecoversAfterExceptionDuringSerialization() {
16021603
value = "org.elasticsearch.cluster.coordination.ClusterFormationFailureHelper:WARN"
16031604
)
16041605
public void testLogsWarningPeriodicallyIfClusterNotFormed() {
1606+
testLogsWarningPeriodicallyIfClusterNotFormed(
1607+
"master not discovered or elected yet, an election requires at least 2 nodes with ids from [",
1608+
nodeId -> "*have only discovered non-quorum *" + nodeId + "*discovery will continue*"
1609+
);
1610+
}
1611+
1612+
protected void testLogsWarningPeriodicallyIfClusterNotFormed(String expectedMessageStart, UnaryOperator<String> discoveryMessageFn) {
16051613
final long warningDelayMillis;
16061614
final Settings settings;
16071615
if (randomBoolean()) {
@@ -1645,10 +1653,7 @@ public void testLogsWarningPeriodicallyIfClusterNotFormed() {
16451653
@Override
16461654
public void match(LogEvent event) {
16471655
final String message = event.getMessage().getFormattedMessage();
1648-
assertThat(
1649-
message,
1650-
startsWith("master not discovered or elected yet, an election requires at least 2 nodes with ids from [")
1651-
);
1656+
assertThat(message, startsWith(expectedMessageStart));
16521657

16531658
final List<ClusterNode> matchingNodes = cluster.clusterNodes.stream()
16541659
.filter(
@@ -1659,13 +1664,7 @@ public void match(LogEvent event) {
16591664
.toList();
16601665
assertThat(matchingNodes, hasSize(1));
16611666

1662-
assertTrue(
1663-
message,
1664-
Regex.simpleMatch(
1665-
"*have only discovered non-quorum *" + matchingNodes.get(0).toString() + "*discovery will continue*",
1666-
message
1667-
)
1668-
);
1667+
assertTrue(message, Regex.simpleMatch(discoveryMessageFn.apply(matchingNodes.get(0).toString()), message));
16691668

16701669
nodesLogged.add(matchingNodes.get(0).getLocalNode());
16711670
}

0 commit comments

Comments
 (0)