Skip to content

Commit 753726c

Browse files
Safer Wait for Snapshot Success in ClusterPrivilegeTests (#40943)
* Safer Wait for Snapshot Success in ClusterPrivilegeTests * The snapshot state returned by the API might become SUCCESS before it's fully removed from the cluster state. * We should fix this race in the transport API but it's not trivial and will be part of the incoming big round of refactoring the repository interaction, this added check fixes the test for now * closes #38030
1 parent a2c35a7 commit 753726c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/integration/ClusterPrivilegeTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
package org.elasticsearch.integration;
77

88
import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotsStatusResponse;
9+
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
910
import org.elasticsearch.client.Request;
1011
import org.elasticsearch.cluster.SnapshotsInProgress;
1112
import org.elasticsearch.common.Strings;
1213
import org.elasticsearch.common.settings.SecureString;
1314
import org.elasticsearch.common.settings.Settings;
1415
import org.elasticsearch.xpack.core.security.authc.support.Hasher;
16+
import org.hamcrest.Matchers;
1517
import org.junit.AfterClass;
1618
import org.junit.BeforeClass;
1719

@@ -139,7 +141,6 @@ public void testThatClusterPrivilegesWorkAsExpectedViaHttp() throws Exception {
139141
assertAccessIsDenied("user_d", "PUT", "/_cluster/settings", "{ \"transient\" : { \"search.default_search_timeout\": \"1m\" } }");
140142
}
141143

142-
@AwaitsFix( bugUrl = "https://github.com/elastic/elasticsearch/issues/38030")
143144
public void testThatSnapshotAndRestore() throws Exception {
144145
String repoJson = Strings.toString(jsonBuilder().startObject().field("type", "fs").startObject("settings").field("location",
145146
repositoryLocation.toString()).endObject().endObject());
@@ -203,6 +204,11 @@ private void waitForSnapshotToFinish(String repo, String snapshot) throws Except
203204
assertBusy(() -> {
204205
SnapshotsStatusResponse response = client().admin().cluster().prepareSnapshotStatus(repo).setSnapshots(snapshot).get();
205206
assertThat(response.getSnapshots().get(0).getState(), is(SnapshotsInProgress.State.SUCCESS));
207+
// The status of the snapshot in the repository can become SUCCESS before it is fully finalized in the cluster state so wait for
208+
// it to disappear from the cluster state as well
209+
SnapshotsInProgress snapshotsInProgress =
210+
client().admin().cluster().state(new ClusterStateRequest()).get().getState().custom(SnapshotsInProgress.TYPE);
211+
assertThat(snapshotsInProgress.entries(), Matchers.empty());
206212
});
207213
}
208214
}

0 commit comments

Comments
 (0)