Skip to content

tests: fix flaky test caused by rapid IO reading and writing #2221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/oauth/src/state-stores/spec-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ export class StateStoreChaiTestRunner {
it('should detect multiple consumption', async () => {
const { stateStore } = this;
const installUrlOptions = { scopes: ['channels:read'] };
for (let i = 0; i < 200; i++) {
for (let i = 0; i < 100; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is reducing the limit by 100 an arbitrary choice for testing or is there a reason behind it?

// generate other states
await stateStore.generateStateParam(installUrlOptions, new Date());
const date = new Date();
await stateStore.generateStateParam(installUrlOptions, date);
console.log('\tgenerateStateParam:', i, 100, date);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is this 100 the same as the loop above? If so, it may be good to put it into a variable and document why we chose 100 to avoid a future regression.

}
const state = await stateStore.generateStateParam(installUrlOptions, new Date());

// NOTE: wait 0.5 second to ensure IO operations completed
await new Promise((resolve, _) => setTimeout(resolve, 500));
console.log('\tsetTimeout: complete');

const result = await stateStore.verifyStateParam(new Date(), state);
assert.exists(result);
let expectedlyReturnedResult: InstallURLOptions = { scopes: [] };
Expand All @@ -68,7 +75,7 @@ export class StateStoreChaiTestRunner {
} catch (e: any) {
assert.equal(e.code, 'slack_oauth_invalid_state', `${state} ${JSON.stringify(expectedlyReturnedResult)}`);
}
}).timeout(4000); // https://github.com/slackapi/node-slack-sdk/issues/2159#issuecomment-2749367820
}).timeout(5000); // https://github.com/slackapi/node-slack-sdk/issues/2159#issuecomment-2749367820
}
});
}
Expand Down