Skip to content

Commit b50f784

Browse files
authored
Fixes retry failed managed index cypress test (opensearch-project#125)
Signed-off-by: Drew Baugher <46505179+dbbaughe@users.noreply.github.com>
1 parent e3b6e0d commit b50f784

File tree

4 files changed

+82
-15
lines changed

4 files changed

+82
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"policy": {
3+
"description": "A simple description",
4+
"default_state": "hot",
5+
"states": [
6+
{
7+
"name": "hot",
8+
"actions": [
9+
{
10+
"rollover": {}
11+
}
12+
],
13+
"transitions": [
14+
{
15+
"state_name": "cold",
16+
"conditions": {
17+
"min_index_age": "30d"
18+
}
19+
}
20+
]
21+
},
22+
{
23+
"name": "cold",
24+
"actions": [
25+
{
26+
"replica_count": {
27+
"number_of_replicas": 2
28+
}
29+
}
30+
],
31+
"transitions": []
32+
}
33+
]
34+
}
35+
}

cypress/integration/managed_indices_spec.js

+35-14
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626

2727
import { PLUGIN_NAME } from "../support/constants";
2828
import samplePolicy from "../fixtures/sample_policy";
29+
import sampleRolloverPolicy from "../fixtures/sample_rollover_policy";
2930
import sampleDataStreamPolicy from "../fixtures/sample_data_stream_policy.json";
3031

3132
const POLICY_ID = "test_policy_id";
3233
const POLICY_ID_2 = "test_policy_id_2";
34+
const POLICY_ID_ROLLOVER = "test_policy_rollover";
3335
const SAMPLE_INDEX = "sample_index";
36+
const SAMPLE_INDEX_ROLLOVER = "sample_index-01";
3437

3538
describe("Managed indices", () => {
3639
beforeEach(() => {
@@ -45,8 +48,9 @@ describe("Managed indices", () => {
4548
cy.visit(`${Cypress.env("opensearch_dashboards")}/app/${PLUGIN_NAME}#/managed-indices`);
4649

4750
// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
48-
// TODO flaky: page may not rendered right with below line
49-
cy.contains("Rows per page", { timeout: 60000 });
51+
cy.contains("Edit rollover alias", { timeout: 60000 });
52+
53+
cy.get('[data-test-subj="toastCloseButton"]').click({ force: true });
5054
});
5155

5256
describe("can have policies removed", () => {
@@ -80,31 +84,46 @@ describe("Managed indices", () => {
8084
});
8185
});
8286

83-
describe.skip("can have policies retried", () => {
87+
describe("can have policies retried", () => {
8488
before(() => {
8589
cy.deleteAllIndices();
86-
// Add a non-existent policy to the index
87-
cy.createIndex(SAMPLE_INDEX, POLICY_ID);
88-
// Speed up execution time to happen in a few seconds
89-
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX);
90+
// Create a policy that rolls over
91+
cy.createPolicy(POLICY_ID_ROLLOVER, sampleRolloverPolicy);
92+
// Create index with alias to rollover
93+
cy.createIndex(SAMPLE_INDEX_ROLLOVER, POLICY_ID_ROLLOVER, { aliases: { "retry-rollover-alias": {} } });
9094
});
9195

9296
it("successfully", () => {
9397
// Confirm we have initial policy
94-
cy.contains(POLICY_ID);
98+
cy.contains(POLICY_ID_ROLLOVER);
99+
100+
// Speed up execution time to happen in a few seconds
101+
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX_ROLLOVER);
95102

96103
// Wait up to 5 seconds for the managed index to execute
97104
// eslint-disable-next-line cypress/no-unnecessary-waiting
98105
cy.wait(5000).reload();
106+
cy.get('[data-test-subj="toastCloseButton"]').click({ force: true });
107+
108+
// Confirm managed index successfully initialized the policy
109+
cy.contains("Successfully initialized", { timeout: 20000 });
110+
111+
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX_ROLLOVER);
112+
113+
// Wait up to 5 seconds for managed index to execute
114+
// eslint-disable-next-line cypress/no-unnecessary-waiting
115+
cy.wait(5000).reload();
116+
cy.get('[data-test-subj="toastCloseButton"]').click({ force: true });
99117

100118
// Confirm we have a Failed execution, wait up to 20 seconds as OSD takes a while to load
101119
cy.contains("Failed", { timeout: 20000 });
120+
cy.contains("Missing rollover_alias");
102121

103-
// Create the policy we were missing
104-
cy.createPolicy(POLICY_ID, samplePolicy);
122+
// Add rollover alias
123+
cy.updateIndexSettings(SAMPLE_INDEX_ROLLOVER, { "plugins.index_state_management.rollover_alias": "retry-rollover-alias" });
105124

106125
// Select checkbox for our managed index
107-
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({ force: true });
126+
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX_ROLLOVER}"]`).check({ force: true });
108127

109128
// Click the retry policy button
110129
cy.get(`[data-test-subj="Retry policyButton"]`).click({ force: true });
@@ -117,19 +136,21 @@ describe("Managed indices", () => {
117136

118137
// Reload the page
119138
cy.reload();
139+
cy.get('[data-test-subj="toastCloseButton"]').click({ force: true });
120140

121141
// Confirm we see managed index attempting to retry, give 20 seconds for OSD load
122142
cy.contains("Pending retry of failed managed index", { timeout: 20000 });
123143

124144
// Speed up next execution of managed index
125-
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX);
145+
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX_ROLLOVER);
126146

127147
// Wait up to 5 seconds for managed index to execute
128148
// eslint-disable-next-line cypress/no-unnecessary-waiting
129149
cy.wait(5000).reload();
150+
cy.get('[data-test-subj="toastCloseButton"]').click({ force: true });
130151

131-
// Confirm managed index successfully initialized the policy
132-
cy.contains("Successfully initialized", { timeout: 20000 });
152+
// Confirm managed index successfully rolled over
153+
cy.contains("Successfully rolled over", { timeout: 20000 });
133154
});
134155
});
135156

cypress/support/commands.js

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ Cypress.Commands.add("getIndexSettings", (index) => {
112112
cy.request("GET", `${Cypress.env("opensearch")}/${index}/_settings`);
113113
});
114114

115+
Cypress.Commands.add("updateIndexSettings", (index, settings) => {
116+
cy.request("PUT", `${Cypress.env("opensearch")}/${index}/_settings`, settings);
117+
});
118+
115119
Cypress.Commands.add("updateManagedIndexConfigStartTime", (index) => {
116120
// Creating closure over startTime so it's not calculated until actual update_by_query call
117121
// eslint-disable-next-line cypress/no-unnecessary-waiting

cypress/support/index.d.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ declare namespace Cypress {
3131
/**
3232
* Deletes all indices in cluster
3333
* @example
34-
* cy.wipeCluster()
34+
* cy.deleteAllIndices()
3535
*/
3636
deleteAllIndices(): Chainable<any>;
3737

@@ -49,6 +49,13 @@ declare namespace Cypress {
4949
*/
5050
getIndexSettings(index: string): Chainable<any>;
5151

52+
/**
53+
* Updates settings for index
54+
* @example
55+
* cy.updateIndexSettings("some_index", settings)
56+
*/
57+
updateIndexSettings(index: string, settings: object): Chainable<any>;
58+
5259
/**
5360
* Updated the managed index config's start time to
5461
* make it run in 3 seconds after calling this.

0 commit comments

Comments
 (0)