@@ -290,6 +290,54 @@ describe.skipIf(!nextVersionSatisfies('>=15.3.0-canary.13'))('use cache', () =>
290290 pageComponentTimeShouldBeEqual : false ,
291291 } )
292292 } )
293+
294+ test . skipIf ( ! nextVersionSatisfies ( '>=16.0.0-alpha.0' ) ) < FixtureTestContext > (
295+ 'invalidating tag with SWR on one lambda result in invalidating them on all lambdas' ,
296+ async ( ) => {
297+ const url = `${ routeRoot } /different-lambdas-tag-invalidation`
298+
299+ const { invokeFunction : invokeFunctionLambda1 } = await loadSandboxedFunction ( ctx )
300+ const { invokeFunction : invokeFunctionLambda2 } = await loadSandboxedFunction ( ctx )
301+
302+ const call1 = await invokeFunctionLambda1 ( { url } )
303+ expect ( call1 ) . not . toBeCacheableResponse ( )
304+
305+ await invokeFunctionLambda2 ( {
306+ url : `/api/revalidate/${ useCacheTagPrefix } /${ url } ?expire=5` ,
307+ } )
308+
309+ const call2 = await invokeFunctionLambda1 ( { url } )
310+ expect ( call2 ) . toHaveExpectedCachingBehavior (
311+ call1 ,
312+ // if we hit before 5 second expire timeframe passes, we expect to get stale response
313+ expectedCachingBehaviorWhenUseCacheRegenerates ,
314+ )
315+
316+ const call3 = await invokeFunctionLambda1 ( { url } )
317+ expect ( call3 ) . toHaveExpectedCachingBehavior ( call2 , {
318+ // previous request should trigger revalidation in background and cause everything to be fresh on this request
319+ getDataTimeShouldBeEqual : false ,
320+ resultWrapperComponentTimeShouldBeEqual : false ,
321+ pageComponentTimeShouldBeEqual : false ,
322+ } )
323+
324+ await invokeFunctionLambda2 ( {
325+ url : `/api/revalidate/${ useCacheTagPrefix } /${ url } ?expire=5` ,
326+ } )
327+
328+ // let's sleep for expire period to test that expire period is honored
329+ await new Promise ( ( resolve ) => setTimeout ( resolve , 6000 ) )
330+
331+ const call4 = await invokeFunctionLambda1 ( { url } )
332+ expect ( call4 ) . toHaveExpectedCachingBehavior ( call3 , {
333+ // we are not getting stale response here because we issued request after expire period
334+ // so everything should be fresh
335+ getDataTimeShouldBeEqual : false ,
336+ resultWrapperComponentTimeShouldBeEqual : false ,
337+ pageComponentTimeShouldBeEqual : false ,
338+ } )
339+ } ,
340+ )
293341 } )
294342
295343 describe ( 'TTL=5 seconds' , ( ) => {
0 commit comments