Fix NullPointerExceptions failing TransportClusterStateActionDisruptionIT (#127523)

Replaces the use of InternalTestCluster.getMasterName() with a
ClusterServiceUtils.addTemporaryStateListener() call that waits
for a new master node other than the previous master node.
InternalTestCluster.getMasterName() is not safe to use in
unstable clusters, per PR 127213.

Closes #127466
Closes #127443
Closes #127424
Closes #127423
Closes #127422
This commit is contained in:
Jeremy Dahlgren 2025-04-30 07:26:44 -04:00 committed by GitHub
parent ba95390895
commit de68cb0b0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 16 deletions

View File

@ -429,18 +429,9 @@ tests:
- class: org.elasticsearch.xpack.esql.heap_attack.HeapAttackIT
method: testLookupExplosionNoFetch
issue: https://github.com/elastic/elasticsearch/issues/127365
- class: org.elasticsearch.action.admin.cluster.state.TransportClusterStateActionDisruptionIT
method: testNonLocalRequestAlwaysFindsMasterAndWaitsForMetadata
issue: https://github.com/elastic/elasticsearch/issues/127422
- class: org.elasticsearch.xpack.esql.qa.single_node.PushQueriesIT
method: testPushCaseInsensitiveEqualityOnDefaults
issue: https://github.com/elastic/elasticsearch/issues/127431
- class: org.elasticsearch.action.admin.cluster.state.TransportClusterStateActionDisruptionIT
method: testLocalRequestAlwaysSucceeds
issue: https://github.com/elastic/elasticsearch/issues/127423
- class: org.elasticsearch.action.admin.cluster.state.TransportClusterStateActionDisruptionIT
method: testLocalRequestWaitsForMetadata
issue: https://github.com/elastic/elasticsearch/issues/127466
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeIT
method: test
issue: https://github.com/elastic/elasticsearch/issues/127536

View File

@ -28,17 +28,16 @@ import org.elasticsearch.transport.TransportService;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
@ESIntegTestCase.ClusterScope(numDataNodes = 0, scope = ESIntegTestCase.Scope.TEST)
public class TransportClusterStateActionDisruptionIT extends ESIntegTestCase {
@ -212,11 +211,12 @@ public class TransportClusterStateActionDisruptionIT extends ESIntegTestCase {
}
}
assertBusy(() -> {
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
final String claimedMasterName = internalCluster().getMasterName(nonMasterNode);
assertThat(claimedMasterName, not(equalTo(masterName)));
});
awaitClusterState(
logger,
nonMasterNode,
state -> Optional.ofNullable(state.nodes().getMasterNode()).map(m -> m.getName().equals(masterName) == false).orElse(false)
);
shutdown.set(true);
assertingThread.join();