Skip to content

Commit

Permalink
Fix test failure introduced in #75917
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DaveCTurner committed Aug 3, 2021
1 parent 15933c0 commit 2b97cc8
Showing 1 changed file with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Custom> {
Expand Down Expand Up @@ -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\":[]}]}"
)
)
);
}
Expand Down

0 comments on commit 2b97cc8

Please sign in to comment.