graphile / starter

Opinionated SaaS quick-start with pre-built user account and organization system for full-stack application development in React, Node.js, GraphQL and PostgreSQL. Powered by PostGraphile, TypeScript, Apollo Client, Graphile Worker, Graphile Migrate, GraphQL Code Generator, Ant Design and Next.js
https://graphile-starter.herokuapp.com
Other
1.73k stars 218 forks source link

Add cypress test for subscription update of user verification #307

Closed fnimick closed 2 years ago

fnimick commented 2 years ago

Description

Adds a test to confirm that the current user subscription used for displaying validation status correctly updates the UI when database modifications are made.

Performance impact

None.

Security impact

None.

Checklist

N/A - this is a test-only change.

fnimick commented 2 years ago

@benjie the cy.wait commands are actually necessary in this case - the websocket connection is explicitly reset after a session change in login and register, and without the wait commands, the database change potentially happens before the websocket reconnects and therefore the test fails as the UI never updates. It's a race condition which is extremely unlikely to happen in the real world since it involves a session being created and the user record being modified within a few milliseconds of each other.

I initially tried to increase the timeout on the cypress assertions, before I realized what was happening here - the issue is a race condition on the UI side which basically can only occur in a test scenario. The key here is to wait before making the database change after session creation, to allow the websocket to reconnect - otherwise, the database change may or may not be propagated to the UI since there is a race condition between the database change and the socket reconnection.

benjie commented 2 years ago

Okay that makes sense; it's suboptimal but I doubt it's worth the effort to fix (which could involve having the client write something to window on reconnect and having cypress poll for it or similar strategy) :+1: