Skip to content

Commit

Permalink
Fixes retry failed managed index cypress test (opensearch-project#125)
Browse files Browse the repository at this point in the history
Signed-off-by: Drew Baugher <[email protected]>
  • Loading branch information
dbbaughe authored and Annie Lee committed Feb 17, 2022
1 parent 6464a2e commit c59ef48
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 15 deletions.
35 changes: 35 additions & 0 deletions cypress/fixtures/sample_rollover_policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"policy": {
"description": "A simple description",
"default_state": "hot",
"states": [
{
"name": "hot",
"actions": [
{
"rollover": {}
}
],
"transitions": [
{
"state_name": "cold",
"conditions": {
"min_index_age": "30d"
}
}
]
},
{
"name": "cold",
"actions": [
{
"replica_count": {
"number_of_replicas": 2
}
}
],
"transitions": []
}
]
}
}
49 changes: 35 additions & 14 deletions cypress/integration/managed_indices_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@

import { PLUGIN_NAME } from "../support/constants";
import samplePolicy from "../fixtures/sample_policy";
import sampleRolloverPolicy from "../fixtures/sample_rollover_policy";
import sampleDataStreamPolicy from "../fixtures/sample_data_stream_policy.json";

const POLICY_ID = "test_policy_id";
const POLICY_ID_2 = "test_policy_id_2";
const POLICY_ID_ROLLOVER = "test_policy_rollover";
const SAMPLE_INDEX = "sample_index";
const SAMPLE_INDEX_ROLLOVER = "sample_index-01";

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

// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
// TODO flaky: page may not rendered right with below line
cy.contains("Rows per page", { timeout: 60000 });
cy.contains("Edit rollover alias", { timeout: 60000 });

cy.get('[data-test-subj="toastCloseButton"]').click({ force: true });
});

describe("can have policies removed", () => {
Expand Down Expand Up @@ -80,31 +84,46 @@ describe("Managed indices", () => {
});
});

describe.skip("can have policies retried", () => {
describe("can have policies retried", () => {
before(() => {
cy.deleteAllIndices();
// Add a non-existent policy to the index
cy.createIndex(SAMPLE_INDEX, POLICY_ID);
// Speed up execution time to happen in a few seconds
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX);
// Create a policy that rolls over
cy.createPolicy(POLICY_ID_ROLLOVER, sampleRolloverPolicy);
// Create index with alias to rollover
cy.createIndex(SAMPLE_INDEX_ROLLOVER, POLICY_ID_ROLLOVER, { aliases: { "retry-rollover-alias": {} } });
});

it("successfully", () => {
// Confirm we have initial policy
cy.contains(POLICY_ID);
cy.contains(POLICY_ID_ROLLOVER);

// Speed up execution time to happen in a few seconds
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX_ROLLOVER);

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

// Confirm managed index successfully initialized the policy
cy.contains("Successfully initialized", { timeout: 20000 });

cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX_ROLLOVER);

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

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

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

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

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

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

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

// Speed up next execution of managed index
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX);
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX_ROLLOVER);

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

// Confirm managed index successfully initialized the policy
cy.contains("Successfully initialized", { timeout: 20000 });
// Confirm managed index successfully rolled over
cy.contains("Successfully rolled over", { timeout: 20000 });
});
});

Expand Down
4 changes: 4 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ Cypress.Commands.add("getIndexSettings", (index) => {
cy.request("GET", `${Cypress.env("opensearch")}/${index}/_settings`);
});

Cypress.Commands.add("updateIndexSettings", (index, settings) => {
cy.request("PUT", `${Cypress.env("opensearch")}/${index}/_settings`, settings);
});

Cypress.Commands.add("updateManagedIndexConfigStartTime", (index) => {
// Creating closure over startTime so it's not calculated until actual update_by_query call
// eslint-disable-next-line cypress/no-unnecessary-waiting
Expand Down
9 changes: 8 additions & 1 deletion cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ declare namespace Cypress {
/**
* Deletes all indices in cluster
* @example
* cy.wipeCluster()
* cy.deleteAllIndices()
*/
deleteAllIndices(): Chainable<any>;

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

/**
* Updates settings for index
* @example
* cy.updateIndexSettings("some_index", settings)
*/
updateIndexSettings(index: string, settings: object): Chainable<any>;

/**
* Updated the managed index config's start time to
* make it run in 3 seconds after calling this.
Expand Down

0 comments on commit c59ef48

Please sign in to comment.