@@ -129,74 +129,15 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })(
129129 expect ( tokenRequests . length ) . toBe ( 1 ) ;
130130 } ) ;
131131
132- /**
133- * Test Flow:
134- * 1. Open two tabs with the same browser context (shared cookies)
135- * 2. Sign in on tab1, reload tab2 to pick up the session
136- * 3. Both tabs hydrate their token cache with the session token
137- * 4. Start counting /tokens requests, then wait for the timers to fire
138- * 5. Assert only 1 /tokens request was made (not 2)
139- */
140- test ( 'multi-tab scheduled refreshes are deduped to a single request' , async ( { context } ) => {
141- test . setTimeout ( 90_000 ) ;
142-
143- const page1 = await context . newPage ( ) ;
144- const page2 = await context . newPage ( ) ;
145-
146- await page1 . goto ( app . serverUrl ) ;
147- await page2 . goto ( app . serverUrl ) ;
148-
149- await page1 . waitForFunction ( ( ) => ( window as any ) . Clerk ?. loaded ) ;
150- await page2 . waitForFunction ( ( ) => ( window as any ) . Clerk ?. loaded ) ;
151-
152- const u1 = createTestUtils ( { app, page : page1 } ) ;
153- await u1 . po . signIn . goTo ( ) ;
154- await u1 . po . signIn . setIdentifier ( fakeUser . email ) ;
155- await u1 . po . signIn . continue ( ) ;
156- await u1 . po . signIn . setPassword ( fakeUser . password ) ;
157- await u1 . po . signIn . continue ( ) ;
158- await u1 . po . expect . toBeSignedIn ( ) ;
159-
160- // eslint-disable-next-line playwright/no-wait-for-timeout
161- await page1 . waitForTimeout ( 1000 ) ;
162-
163- await page2 . reload ( ) ;
164- await page2 . waitForFunction ( ( ) => ( window as any ) . Clerk ?. loaded ) ;
165-
166- const u2 = createTestUtils ( { app, page : page2 } ) ;
167- await u2 . po . expect . toBeSignedIn ( ) ;
168-
169- // Both tabs are now signed in and have hydrated their token caches
170- // via Session constructor -> #hydrateCache, each with an independent
171- // onRefresh timer that fires at ~43s (TTL 60s - 15s leeway - 2s lead).
172- // Start counting /tokens requests from this point.
173- const refreshRequests : string [ ] = [ ] ;
174- await context . route ( '**/v1/client/sessions/*/tokens*' , async route => {
175- refreshRequests . push ( route . request ( ) . url ( ) ) ;
176- await route . continue ( ) ;
177- } ) ;
178-
179- // Wait for proactive refresh timers to fire.
180- // Default token TTL is 60s; onRefresh fires at 60 - 15 - 2 = 43s from iat.
181- // We wait 50s to give comfortable buffer, this includes the broadcast delay.
182- //
183- // Uses page.evaluate instead of page.waitForTimeout to avoid
184- // the global actionTimeout (10s) silently capping the wait.
185- await page1 . evaluate ( ( ) => new Promise ( resolve => setTimeout ( resolve , 50_000 ) ) ) ;
186-
187- // Only one tab should have made a /tokens request; the other tab should have
188- // received the refreshed token via BroadcastChannel.
189- expect ( refreshRequests . length ) . toBe ( 1 ) ;
190-
191- // Both tabs should still have valid tokens after the refresh cycle
192- const [ page1Token , page2Token ] = await Promise . all ( [
193- page1 . evaluate ( ( ) => ( window as any ) . Clerk . session ?. getToken ( ) ) ,
194- page2 . evaluate ( ( ) => ( window as any ) . Clerk . session ?. getToken ( ) ) ,
195- ] ) ;
196-
197- expect ( page1Token ) . toBeTruthy ( ) ;
198- expect ( page2Token ) . toBeTruthy ( ) ;
199- expect ( page1Token ) . toBe ( page2Token ) ;
200- } ) ;
132+ // The previous "multi-tab scheduled refreshes are deduped to a single request"
133+ // test relied on the proactive-refresh setTimeout firing within a 50s wall-clock
134+ // window, which assumed JWT TTL = 60s. The dev test instance now issues 300s
135+ // tokens, so the timer fires at ~283s and the test never reached it. The
136+ // BroadcastChannel-based dedup it was checking is already covered by the
137+ // "multi-tab token sharing works when clearing the cache" test above, which
138+ // explicitly triggers a fetch via `getToken({ skipCache: true })`. The
139+ // proactive-refresh timer scheduling itself (the math, the leeway, the
140+ // re-registration on success) is best validated by unit tests that mock
141+ // `setTimeout` rather than depending on real time in a real browser.
201142 } ,
202143) ;
0 commit comments