From 2b97cc8ed7db55183d07318cadd11bfa63d70532 Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 3 Aug 2021 12:37:22 +0100 Subject: [PATCH] Fix test failure introduced in #75917 In #75917 we introduced an assertion that relied on the order of the shards in the JSON representation of a `SnapshotsInProgress` but in fact we might end up with the shards in either order. This commit weakens the assertion to fix the test. --- ...SnapshotsInProgressSerializationTests.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/snapshots/SnapshotsInProgressSerializationTests.java b/server/src/test/java/org/elasticsearch/snapshots/SnapshotsInProgressSerializationTests.java index 3bc23b01f280a..9850d3802b70e 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SnapshotsInProgressSerializationTests.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SnapshotsInProgressSerializationTests.java @@ -42,6 +42,7 @@ import java.util.stream.Stream; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; public class SnapshotsInProgressSerializationTests extends AbstractDiffableWireSerializationTestCase { @@ -398,17 +399,31 @@ public void testXContent() throws IOException { String json = Strings.toString(builder); assertThat( json, - equalTo( - "{\"snapshots\":[{\"repository\":\"repo\",\"snapshot\":\"name\",\"uuid\":\"uuid\"," - + "\"include_global_state\":true,\"partial\":true,\"state\":\"SUCCESS\"," - + "\"indices\":[{\"name\":\"index\",\"id\":\"uuid\"}],\"start_time\":\"1970-01-01T00:20:34.567Z\"," - + "\"start_time_millis\":1234567,\"repository_state_id\":0,\"shards\":[" - + "{\"index\":{\"index_name\":\"index\",\"index_uuid\":\"uuid\"},\"shard\":0,\"state\":\"SUCCESS\"," - + "\"generation\":\"shardgen\",\"node\":\"nodeId\"," - + "\"result\":{\"generation\":\"shardgen\",\"size\":\"1b\",\"size_in_bytes\":1,\"segments\":1}}," - + "{\"index\":{\"index_name\":\"index\",\"index_uuid\":\"uuid\"},\"shard\":1,\"state\":\"FAILED\"," - + "\"generation\":\"fail-gen\",\"node\":\"nodeId\",\"reason\":\"failure-reason\"}" - + "],\"feature_states\":[],\"data_streams\":[]}]}" + anyOf( + equalTo( + "{\"snapshots\":[{\"repository\":\"repo\",\"snapshot\":\"name\",\"uuid\":\"uuid\"," + + "\"include_global_state\":true,\"partial\":true,\"state\":\"SUCCESS\"," + + "\"indices\":[{\"name\":\"index\",\"id\":\"uuid\"}],\"start_time\":\"1970-01-01T00:20:34.567Z\"," + + "\"start_time_millis\":1234567,\"repository_state_id\":0,\"shards\":[" + + "{\"index\":{\"index_name\":\"index\",\"index_uuid\":\"uuid\"},\"shard\":0,\"state\":\"SUCCESS\"," + + "\"generation\":\"shardgen\",\"node\":\"nodeId\"," + + "\"result\":{\"generation\":\"shardgen\",\"size\":\"1b\",\"size_in_bytes\":1,\"segments\":1}}," + + "{\"index\":{\"index_name\":\"index\",\"index_uuid\":\"uuid\"},\"shard\":1,\"state\":\"FAILED\"," + + "\"generation\":\"fail-gen\",\"node\":\"nodeId\",\"reason\":\"failure-reason\"}" + + "],\"feature_states\":[],\"data_streams\":[]}]}" + ), // or the shards might be in the other order: + equalTo( + "{\"snapshots\":[{\"repository\":\"repo\",\"snapshot\":\"name\",\"uuid\":\"uuid\"," + + "\"include_global_state\":true,\"partial\":true,\"state\":\"SUCCESS\"," + + "\"indices\":[{\"name\":\"index\",\"id\":\"uuid\"}],\"start_time\":\"1970-01-01T00:20:34.567Z\"," + + "\"start_time_millis\":1234567,\"repository_state_id\":0,\"shards\":[" + + "{\"index\":{\"index_name\":\"index\",\"index_uuid\":\"uuid\"},\"shard\":1,\"state\":\"FAILED\"," + + "\"generation\":\"fail-gen\",\"node\":\"nodeId\",\"reason\":\"failure-reason\"}," + + "{\"index\":{\"index_name\":\"index\",\"index_uuid\":\"uuid\"},\"shard\":0,\"state\":\"SUCCESS\"," + + "\"generation\":\"shardgen\",\"node\":\"nodeId\"," + + "\"result\":{\"generation\":\"shardgen\",\"size\":\"1b\",\"size_in_bytes\":1,\"segments\":1}}" + + "],\"feature_states\":[],\"data_streams\":[]}]}" + ) ) ); }