-
Notifications
You must be signed in to change notification settings - Fork 141
Issue #28: Increase sleep timeout to prevent api rate limiting #29
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
Changes from 6 commits
644c747
4eaea60
5e37244
c633ff7
117adb6
82d648f
4de22eb
2e01eb6
647dd29
80c1394
6d87a02
ed94de0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -318,6 +318,104 @@ describe("waitForBuildEndTime", () => { | |
| }); | ||
| expect(test).to.equal(buildReplies.pop().builds[0]); | ||
| }); | ||
|
|
||
| it("waits after being rate limited and tries again", async function() { | ||
| this.timeout(45000); | ||
|
||
| const buildID = "buildID"; | ||
| const nullArn = | ||
| "arn:aws:logs:us-west-2:111122223333:log-group:null:log-stream:null"; | ||
| const cloudWatchLogsArn = | ||
| "arn:aws:logs:us-west-2:111122223333:log-group:/aws/codebuild/CloudWatchLogGroup:log-stream:1234abcd-12ab-34cd-56ef-1234567890ab"; | ||
|
|
||
| const buildReplies = [ | ||
| () => { | ||
| throw { message: "Rate exceeded" }; | ||
| }, | ||
| { builds: [{ id: buildID, logs: { cloudWatchLogsArn } }] }, | ||
| { | ||
| builds: [ | ||
| { id: buildID, logs: { cloudWatchLogsArn }, endTime: "endTime" } | ||
| ] | ||
| } | ||
| ]; | ||
|
|
||
| const sdk = help( | ||
| () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to say leave it now, |
||
| //similar to the ret function in the helper, allows me to throw an error in a function or return a more standard reply | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take a look at: https://sembr.org/ |
||
| let reply = buildReplies.shift(); | ||
|
|
||
| if (typeof reply === "function") return reply(); | ||
| return reply; | ||
| }, | ||
| () => { | ||
| if (!buildReplies.length) { | ||
| return { events: [] }; | ||
| } | ||
|
|
||
| return { events: [{ message: "got one" }] }; | ||
| } | ||
| ); | ||
|
|
||
| const test = await waitForBuildEndTime(sdk, { | ||
seebees marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| id: buildID, | ||
| logs: { cloudWatchLogsArn: nullArn } | ||
| }); | ||
|
|
||
| expect(test.id).to.equal(buildID); | ||
| }); | ||
|
|
||
| it("dies after getting an error from the aws sdk that isn't rate limiting", async function() { | ||
| this.timeout(45000); | ||
| const buildID = "buildID"; | ||
| const nullArn = | ||
| "arn:aws:logs:us-west-2:111122223333:log-group:null:log-stream:null"; | ||
| const cloudWatchLogsArn = | ||
| "arn:aws:logs:us-west-2:111122223333:log-group:/aws/codebuild/CloudWatchLogGroup:log-stream:1234abcd-12ab-34cd-56ef-1234567890ab"; | ||
|
|
||
| const buildReplies = [ | ||
| () => { | ||
| throw { message: "Some AWS error" }; | ||
| }, | ||
| { builds: [{ id: buildID, logs: { cloudWatchLogsArn } }] }, | ||
| { | ||
| builds: [ | ||
| { id: buildID, logs: { cloudWatchLogsArn }, endTime: "endTime" } | ||
| ] | ||
| } | ||
| ]; | ||
|
|
||
| const sdk = help( | ||
| () => { | ||
| //similar to the ret function in the helper, allows me to throw an error in a function or return a more standard reply | ||
| let reply = buildReplies.shift(); | ||
|
|
||
| if (typeof reply === "function") return reply(); | ||
| return reply; | ||
| }, | ||
| () => { | ||
| if (!buildReplies.length) { | ||
| return { events: [] }; | ||
| } | ||
|
|
||
| return { events: [{ message: "got one" }] }; | ||
| } | ||
| ); | ||
|
|
||
| //run the thing and it should fail | ||
| let didFail = false; | ||
|
|
||
| try { | ||
| await waitForBuildEndTime(sdk, { | ||
| id: buildID, | ||
| logs: { cloudWatchLogsArn: nullArn } | ||
| }); | ||
| } catch (err) { | ||
| didFail = true; | ||
| expect(err.message).to.equal("Some AWS error"); | ||
| } | ||
|
|
||
| expect(didFail).to.equal(true); | ||
| }); | ||
| }); | ||
|
|
||
| function help(builds, logs) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.