Skip to content

Commit

Permalink
fix(Searchable): confirm ES data propagate (#8251)
Browse files Browse the repository at this point in the history
  • Loading branch information
sundersc authored Sep 22, 2021
1 parent d17309d commit 8e5c791
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,32 @@ const createEntries = async () => {
await runQuery(getCreatePostsMutation('testuser', 'test title', 170, 30, 77.7, true));
// Waiting for the ES Cluster + Streaming Lambda infra to be setup
await cf.wait(120, () => Promise.resolve());
await waitForESPropagate();
};

const waitForESPropagate = async (initialWaitSeconds = 5, maxRetryCount = 5 ) => {
const expectedCount = 8;
let waitInMilliseconds = initialWaitSeconds * 1000;
let currentRetryCount = 0;
let searchResponse;

do {
await new Promise(r => setTimeout(r, waitInMilliseconds));
searchResponse = await GRAPHQL_CLIENT.query(
`query {
searchPosts {
items {
id
}
}
}`,
{},
);
currentRetryCount += 1;
waitInMilliseconds = waitInMilliseconds * 2;
} while (searchResponse.data.searchPosts?.items?.length < expectedCount && currentRetryCount <= maxRetryCount);
}

beforeAll(async () => {
const validSchema = `
type Post @model @searchable {
Expand Down

0 comments on commit 8e5c791

Please sign in to comment.