-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Use builtin library and add test to verify that delay is actually delaying #613
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -5,9 +5,10 @@ import * as parse from "csv-parse" | |
import { Credentials } from "google-auth-library" | ||
import { drive_v3, google, sheets_v4 } from "googleapis" | ||
import { GaxiosPromise } from "googleapis-common" | ||
import {setTimeout} from "timers/promises" | ||
import * as winston from "winston" | ||
import { getHttpErrorType } from "../../../../error_types/utils" | ||
import { Error, errorWith } from "../../../../hub/action_response" | ||
import { Error, errorWith } from "../../../../hub" | ||
import { GoogleDriveAction } from "../google_drive" | ||
import Drive = drive_v3.Drive | ||
import Sheet = sheets_v4.Sheets | ||
|
@@ -444,10 +445,8 @@ export class GoogleSheetsAction extends GoogleDriveAction { | |
throw `Max retries attempted` | ||
} | ||
|
||
protected async delay(time: number) { | ||
await new Promise<void>((resolve) => { | ||
setTimeout(resolve, time) | ||
}) | ||
async delay(time: number) { | ||
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. What are the units here? |
||
return await setTimeout(time).catch((_) => { winston.error("setTimeout throw!")}) | ||
} | ||
|
||
protected async sheetsClientFromRequest(redirect: string, tokens: Credentials) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -538,6 +538,15 @@ describe(`${action.constructor.name} unit tests`, () => { | |
}) | ||
}) | ||
|
||
describe("delay", () => { | ||
it("will block on await delay", async () => { | ||
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. Can you provide more detail for why this is necessary? 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. the previous implementation, although it looked correct, was not actually delaying retries. I am seeing another area which I missed so I will upload another change to this as well |
||
const start = Date.now() | ||
await action.delay(100) | ||
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. What are the units here? |
||
const end = Date.now() | ||
chai.expect(end - start).to.be.greaterThanOrEqual(10) | ||
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. What are the units here? |
||
}) | ||
}) | ||
|
||
describe("flushRetry", () => { | ||
it("will retry until the MAX_RETRY_LIMIT is reached", (done) => { | ||
const delayStub = sinon.stub(action as any, "delay") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What effect are you achieving here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't particularly matter and then I can actually test the function