|
65 | 65 | import static org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry.SLM_POLICY_NAME;
|
66 | 66 | import static org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry.SLM_TEMPLATE_NAME;
|
67 | 67 | import static org.hamcrest.Matchers.equalTo;
|
| 68 | +import static org.hamcrest.Matchers.greaterThan; |
68 | 69 | import static org.hamcrest.Matchers.hasSize;
|
69 | 70 | import static org.hamcrest.Matchers.instanceOf;
|
70 | 71 | import static org.mockito.Mockito.mock;
|
@@ -136,10 +137,17 @@ public void testThatNonExistingTemplatesAreAddedImmediately() throws Exception {
|
136 | 137 | assertBusy(() -> assertThat(calledTimes.get(), equalTo(registry.getTemplateConfigs().size())));
|
137 | 138 |
|
138 | 139 | calledTimes.set(0);
|
139 |
| - // now delete one template from the cluster state and lets retry |
140 |
| - ClusterChangedEvent newEvent = createClusterChangedEvent(Collections.emptyList(), nodes); |
141 |
| - registry.clusterChanged(newEvent); |
142 |
| - assertBusy(() -> assertThat(calledTimes.get(), equalTo(1))); |
| 140 | + |
| 141 | + // attempting to register the event multiple times as a race condition can yield this test flaky, namely: |
| 142 | + // when calling registry.clusterChanged(newEvent) the templateCreationsInProgress state that the IndexTemplateRegistry maintains |
| 143 | + // might've not yet been updated to reflect that the first template registration was complete, so a second template registration |
| 144 | + // will not be issued anymore, leaving calledTimes to 0 |
| 145 | + assertBusy(() -> { |
| 146 | + // now delete one template from the cluster state and lets retry |
| 147 | + ClusterChangedEvent newEvent = createClusterChangedEvent(Collections.emptyList(), nodes); |
| 148 | + registry.clusterChanged(newEvent); |
| 149 | + assertThat(calledTimes.get(), greaterThan(1)); |
| 150 | + }); |
143 | 151 | }
|
144 | 152 |
|
145 | 153 | public void testThatNonExistingPoliciesAreAddedImmediately() throws Exception {
|
|
0 commit comments