Fix testDataOnlyNodePersistence (#56893)

This test failed if all 1000 top-level `rarely()` calls in the loop returned
`false`, because then we would never set the term of the persisted state. This
commit fixes this by adding an earlier call to `persistedState#setCurrentTerm`.
It also changes the test to clean up the threadpools it starts whether it
passes or fails.
This commit is contained in:
David Turner 2020-05-18 13:54:00 +01:00
parent 74554f1ae8
commit 64280b489b
1 changed files with 89 additions and 80 deletions

View File

@ -49,6 +49,7 @@ import org.elasticsearch.threadpool.TestThreadPool;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import java.io.Closeable;
import java.io.IOError;
import java.io.IOException;
import java.nio.file.Path;
@ -328,13 +329,18 @@ public class GatewayMetaStatePersistedStateTests extends ESTestCase {
}
public void testDataOnlyNodePersistence() throws Exception {
final List<Closeable> cleanup = new ArrayList<>(2);
try {
DiscoveryNode localNode = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Collections.emptyMap(),
Sets.newHashSet(DiscoveryNodeRole.DATA_ROLE), Version.CURRENT);
Settings settings = Settings.builder().put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName.value()).put(
Node.NODE_MASTER_SETTING.getKey(), false).put(Node.NODE_NAME_SETTING.getKey(), "test").build();
final MockGatewayMetaState gateway = new MockGatewayMetaState(localNode);
cleanup.add(gateway);
final TransportService transportService = mock(TransportService.class);
TestThreadPool threadPool = new TestThreadPool("testMarkAcceptedConfigAsCommittedOnDataOnlyNode");
cleanup.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS));
when(transportService.getThreadPool()).thenReturn(threadPool);
ClusterService clusterService = mock(ClusterService.class);
when(clusterService.getClusterSettings()).thenReturn(
@ -356,6 +362,7 @@ public class GatewayMetaStatePersistedStateTests extends ESTestCase {
ClusterState state = createClusterState(randomNonNegativeLong(),
Metadata.builder().coordinationMetadata(coordinationMetadata)
.clusterUUID(randomAlphaOfLength(10)).build());
persistedState.setCurrentTerm(state.term());
persistedState.setLastAcceptedState(state);
assertBusy(() -> assertTrue(gateway.allPendingAsyncStatesWritten()));
@ -408,6 +415,7 @@ public class GatewayMetaStatePersistedStateTests extends ESTestCase {
assertBusy(() -> assertTrue(gateway.allPendingAsyncStatesWritten()));
gateway.close();
assertTrue(cleanup.remove(gateway));
try (CoordinationState.PersistedState reloadedPersistedState = newGatewayPersistedState()) {
assertEquals(currentTerm, reloadedPersistedState.getCurrentTerm());
@ -415,8 +423,9 @@ public class GatewayMetaStatePersistedStateTests extends ESTestCase {
reloadedPersistedState.getLastAcceptedState());
assertNotNull(reloadedPersistedState.getLastAcceptedState().metadata().index(indexName));
}
ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
} finally {
IOUtils.close(cleanup);
}
}
public void testStatePersistenceWithIOIssues() throws IOException {