Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,18 +432,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

# Examples:
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
import org.elasticsearch.discovery.MasterNotDiscoveredException;
import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ClusterServiceUtils;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.transport.MockTransportService;
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 {
Expand Down Expand Up @@ -212,11 +212,13 @@ public void runRepeatedlyWhileChangingMaster(Runnable runnable) throws Exception
}
}

assertBusy(() -> {
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
final String claimedMasterName = internalCluster().getMasterName(nonMasterNode);
assertThat(claimedMasterName, not(equalTo(masterName)));
});
final String nonMasterNode = randomValueOtherThan(masterName, () -> randomFrom(internalCluster().getNodeNames()));
var newMasterNodeListener = ClusterServiceUtils.addTemporaryStateListener(
internalCluster().clusterService(nonMasterNode),
state -> Optional.ofNullable(state.nodes().getMasterNode()).map(m -> m.getName().equals(masterName) == false).orElse(false),
TEST_REQUEST_TIMEOUT
);
safeAwait(newMasterNodeListener, TEST_REQUEST_TIMEOUT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can do this:

Suggested change
var newMasterNodeListener = ClusterServiceUtils.addTemporaryStateListener(
internalCluster().clusterService(nonMasterNode),
state -> Optional.ofNullable(state.nodes().getMasterNode()).map(m -> m.getName().equals(masterName) == false).orElse(false),
TEST_REQUEST_TIMEOUT
);
safeAwait(newMasterNodeListener, TEST_REQUEST_TIMEOUT);
awaitClusterState(
logger,
nonMasterNode,
state -> Optional.ofNullable(state.nodes().getMasterNode()).map(m -> m.getName().equals(masterName) == false).orElse(false)
);

That looks a tiny bit cleaner to me and matches better what we're actually trying to achieve (which is waiting for the cluster state). The only downside is that this changes the timeout as ClusterServiceUtils#awaitClusterState uses a timeout of 30s whereas asserBusy (the old code) uses a default timeout of 10s. I think we'll want to try to reduce that 30s timeout at some point anyway, so I don't see that as a reason not to use that method here.

Also, the logger parameter will likely be removed in the future as well, making this even cleaner (but still only a little bit more).


shutdown.set(true);
assertingThread.join();
Expand Down