Skip to content

Commit a5dc382

Browse files
authored
Fix InternalSnapshotsInfoServiceTests.testErroneousSnapshotShardSizes (elastic#66532)
This test failed few times since elastic#65436 has been merged. Now InternalSnapshotsInfoService now also reroutes after shard fetching failures and because those reroute are executed in the generic thread pool the test should wait for all reroutes to be processed.
1 parent c96b3ba commit a5dc382

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

server/src/test/java/org/elasticsearch/snapshots/InternalSnapshotsInfoServiceTests.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.elasticsearch.common.UUIDs;
4444
import org.elasticsearch.common.collect.ImmutableOpenMap;
4545
import org.elasticsearch.common.settings.Settings;
46+
import org.elasticsearch.common.util.concurrent.CountDown;
4647
import org.elasticsearch.index.Index;
4748
import org.elasticsearch.index.shard.ShardId;
4849
import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
@@ -179,10 +180,18 @@ public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, In
179180
}
180181

181182
public void testErroneousSnapshotShardSizes() throws Exception {
182-
final AtomicInteger reroutes = new AtomicInteger();
183+
final int maxShardsToCreate = scaledRandomIntBetween(10, 500);
184+
185+
final PlainActionFuture<Void> waitForAllReroutesProcessed = new PlainActionFuture<>();
186+
final CountDown reroutes = new CountDown(maxShardsToCreate);
183187
final RerouteService rerouteService = (reason, priority, listener) -> {
184-
reroutes.incrementAndGet();
185-
listener.onResponse(clusterService.state());
188+
try {
189+
listener.onResponse(clusterService.state());
190+
} finally {
191+
if (reroutes.countDown()) {
192+
waitForAllReroutesProcessed.onResponse(null);
193+
}
194+
}
186195
};
187196

188197
final InternalSnapshotsInfoService snapshotsInfoService =
@@ -208,7 +217,6 @@ public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, In
208217
};
209218
when(repositoriesService.repository("_repo")).thenReturn(mockRepository);
210219

211-
final int maxShardsToCreate = scaledRandomIntBetween(10, 500);
212220
final Thread addSnapshotRestoreIndicesThread = new Thread(() -> {
213221
int remainingShards = maxShardsToCreate;
214222
while (remainingShards > 0) {
@@ -251,8 +259,9 @@ public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, In
251259
success ? equalTo(results.get(snapshotShard.getKey())) : equalTo(defaultValue));
252260
}
253261

262+
waitForAllReroutesProcessed.get(60L, TimeUnit.SECONDS);
254263
assertThat("Expecting all snapshot shard size fetches to provide a size", results.size(), equalTo(maxShardsToCreate));
255-
assertThat("Expecting all snapshot shard size fetches to execute a Reroute", reroutes.get(), equalTo(maxShardsToCreate));
264+
assertTrue("Expecting all snapshot shard size fetches to execute a Reroute", reroutes.isCountedDown());
256265
}
257266

258267
public void testNoLongerMaster() throws Exception {

0 commit comments

Comments
 (0)