Fix race condition when setting up server files - #229
Conversation
| await new Promise( process.nextTick ); | ||
| expect( createMainWindow ).not.toHaveBeenCalled(); | ||
| expect( captureExceptionMock ).toHaveBeenCalled(); |
There was a problem hiding this comment.
My best guess is that I wrapped it while authoring the test prior to implementing the error catching logic. Removing this makes sense.
| it( 'should gracefully handle app ready failures when creating a window on activate', () => { | ||
| jest.isolateModules( async () => { | ||
| it( 'should gracefully handle app ready failures when creating a window on activate', async () => { | ||
| await jest.isolateModulesAsync( async () => { |
There was a problem hiding this comment.
Following Jest documentation, we should use the async version of isolateModules when there's async logic involved.
dcalhoun
left a comment
There was a problem hiding this comment.
I was unable to reproduce the referenced error in the trunk branch, but the proposed code changes LGTM. 🚀
| } ); | ||
| } ); | ||
|
|
||
| await setupWPServerFiles().catch( Sentry.captureException ); |
There was a problem hiding this comment.
I suppose there is a (likely very small) possibility that the activate event fires before this promise resolves, as that event handler is adjacent to this scope. That would mean a user could still encounter the targeted error.
Seems like a very unlikely scenario that we do not need to address, but I share it nonetheless.
Lines 251 to 257 in 4aa60ff
There was a problem hiding this comment.
Yeah, I think that would probably be an edge case. I tested adding a delay when executing the ready event, and triggering the ready event by cliking on the dock icon of the Studio app results in an exception. This could be easily addressed by adding a condition in activate event to only create the main window when all the logic performed in ready is complete. I'll do this in a different PR.
Error:
Error occurred in handler for 'getAppGlobals': Error: No handler registered for 'getAppGlobals'
at WebContents.<anonymous> (node:electron/js2c/browser_init:2:78277)
at WebContents.emit (node:events:514:28)
at WebContents.emit (node:domain:488:12)
There was a problem hiding this comment.
I came to realize this might be more common than we expect based on the issue Automattic/dotcom-forge#8016. I'll try to tackle it asap.
| await new Promise( process.nextTick ); | ||
| expect( createMainWindow ).not.toHaveBeenCalled(); | ||
| expect( captureExceptionMock ).toHaveBeenCalled(); |
There was a problem hiding this comment.
My best guess is that I wrapped it while authoring the test prior to implementing the error catching logic. Removing this makes sense.
Related to #76 (comment).
Proposed Changes
setupWPServerFilesto the app's ready event handler. This will ensure that the setup finishes before creating the main window and let the user interact with the app.index.test.tsfile to address issues with async code.Testing Instructions
Note
This issue has been spotted when running E2E tests on Windows. It's unlikely that users have encountered this as it's produced by a combination of slow file disk operations and creating a site quickly after the app is launched.
$HOME/Library/Application Support/Studio/server-files.Pre-merge Checklist