Wait for the download click instead of a fixed timeout in saveCanvas … - #9031
Conversation
Ayush4958
left a comment
There was a problem hiding this comment.
Good work by
Removing arbitrary fixed timeouts and Its nice to duplicate the short mock logic for now as its only needed in 2 files.
If needed on future we can expand it by creating a shared helper function. I had tested this on my end, every test is passed.
LGTM
|
Thanks @Ayush4958 ! |
|
Hi @ksen0 I am very sorry to tag directly and know that you already told me to ping maintainers when its extremely important or after few weeks have passed, but— the three workflows on this PR and on #9012 This one has an approval already and both test files pass locally. Thanks! |
|
@davepagurek Can you have a look when you can to see if it made sense for you. If all looks good, do go ahead and merge. Thanks. |
Resolves #9030
Changes
The four
saveCanvasdownload tests waited on a fixed sleep before asserting:one 500ms sleep in
test/unit/webgl/p5.Framebuffer.jsand three 100ms sleepsin
test/unit/image/downloading.js. The sleep was a guess about how longencoding takes — if it would run long, the assertion would arrive before the anchor
exists and the test fails. That's what the failure in #9030 is: two
createElement('canvas')calls and zero'a'calls, i.e. the download hadn'thappened yet rather than never.
saveCanvascallshtmlCanvas.toBlob(...)and returns immediately, so therewas nothing to await — hence the sleep. But the test already mocks
document.createElementand hands back a fake anchor, andlink.click()isexactly the moment the download happens. So the mock can signal it instead:
onDownloadholds the current test'sresolvemockAnchorElement.clickcalls itdownloadHappened()creates the promise and registers the resolveEach test now subscribes first, calls
saveCanvas, and awaits the click. No durationin the test at all.
onDownloadis reset inbeforeEach.Locally the framebuffer test does ~51ms of real work against the old 500ms
budget, and the three 2D ones 6/18/15ms against 100ms. So CI was running
roughly 10x slower than local, which is plausible on a shared runner with
software WebGL.
Two things I considered and didn't do:
full duration on every passing run.
vi.waitFor(). Its default timeout is 5000ms, above this project's3000ms
testTimeout, so it would need hand-tuning to a duration anyway.The mock wiring is duplicated across the two files itself, rather than extracted to a
shared helper — with two call sites the duplication seemed the right approach than the
indirection, but happy to pull it out if you'd rather.
Note: this touches
test/unit/image/downloading.js, which #9012 also modifies(different suite in the same file). Happy to rebase whichever lands second.
PR Checklist
npm run lintpasses