-
Couldn't load subscription status.
- Fork 6
fix: (polyfill) Fix abort behavior, expected errors and fake tests #51
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
Conversation
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.
These should ideally be refactored to await expect(...).rejects but deferring it to a different PR
|
|
||
| // handle request options | ||
| if (_options.steal === true) { | ||
| if (!self._handleExceptionWhenStealIsTrue(_options, reject)) return; |
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.
This was moved to _handleRequestArgs to consolidate args errors in one place
| ) | ||
| ); | ||
| return false; | ||
| const listener = this._signalOnabort(signal, request); |
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.
Opted for returning a listener instead of mutating request inside _signalOnAbort
| // Flush microtask queue | ||
| await new Promise((resolve) => setTimeout(resolve, 0)); |
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.
This was needed since lock acquisition now yields execution back to the callers scope for a tick to allow sync abortSignal cancellation
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.
Try-catches were removed from all signal tests because they mask failing tests when the function under test doesn't throw. Ideally this change should be made everywhere, but starting here since abortSignal is the main scope of this PR
| ifAvailable: Boolean; | ||
| steal: Boolean; |
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.
Drive-by fix. We expect primitive booleans here and not boolean objects.
| closeSignal?: () => void; | ||
| signal?: AbortSignal; |
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.
Added to allow checking signal before lock acquisition as well as remove listener post-acquisition
| public async request(...args: RequestArgsCase3) { | ||
| const self = this; | ||
| return new Promise(async function (resolve, reject) { | ||
| return new Promise(function (resolve, reject) { |
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.
Promise constructor callbacks should not be async
| private _handleExceptionWhenStealIsTrue( | ||
| _options: LockOptions, | ||
| reject: (reason?: any) => void | ||
| ) { | ||
| if (_options.mode !== LOCK_MODE.EXCLUSIVE) { | ||
| reject( | ||
| new DOMException( | ||
| "Failed to execute 'request' on 'LockManager': The 'steal' option may only be used with 'exclusive' locks." | ||
| ) | ||
| ); | ||
| return false; | ||
| } | ||
| if (_options.ifAvailable === true) { | ||
| reject( | ||
| new DOMException( | ||
| "Failed to execute 'request' on 'LockManager': The 'steal' and 'ifAvailable' options cannot be used together." | ||
| ) | ||
| ); | ||
| return false; |
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.
Moved to _handleRequestArgs to consolidate args errors in one place
|
hi @smartinio I in detail Reviewed your MR, your MR is excellent👍🏻 awesome! Approved! Thank you very much!! |
|
I seems have CI error, could you help fix that? @smartinio ☆⌒(*^-゜)v THX!! |
|
@aermin Thanks. Oh, okay. Having a look at the error |
|
@aermin I don't have enough repository access to see the details of CI errors, but I do see this annotation: "The job was not started because your account is locked due to a billing issue." |
|
hi @smartinio you are right~ I released the new version(0.8.7) for your commits, thanks again!! pls help do the seft-testing in your end side. |
Hi,
Noticed that abort behavior wasn't working as expected and found some issues. While fixing them I also noticed everything was pretty old, so I also took some time to update Node.js, Jest, Typescript and get rid of some vulnerabilities. I've split these into separate commits.
The main culprit that lead me to find issues was the use of
catch+expectin tests. This is dangerous because if the function does not throw, the test will pass. For the signal tests, I've refactored these toawait expect(promise).rejects...but there are more occurrences in other tests.