Unverified Commit b085fafe authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

test: reduce artificial timeouts in runtime prefetch tests (#82276)

the "wait for 500ms" thing was a leftover of me inspecting the test apps
visually, we don't need it anymore and it slows the tests down
unnecessarily
parent 531e9384
...@@ -25,7 +25,7 @@ export default async function Layout({ children }) { ...@@ -25,7 +25,7 @@ export default async function Layout({ children }) {
async function RuntimePrefetchable() { async function RuntimePrefetchable() {
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-layout">{`Cookie from layout: ${cookieValue}`}</div> <div id="cookie-value-layout">{`Cookie from layout: ${cookieValue}`}</div>
......
...@@ -16,7 +16,7 @@ export default function Page() { ...@@ -16,7 +16,7 @@ export default function Page() {
async function RuntimePrefetchable() { async function RuntimePrefetchable() {
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div> <div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
......
...@@ -16,7 +16,7 @@ export default function Page() { ...@@ -16,7 +16,7 @@ export default function Page() {
async function RuntimePrefetchable() { async function RuntimePrefetchable() {
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div> <div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
......
...@@ -26,7 +26,7 @@ export default async function Layout({ children }) { ...@@ -26,7 +26,7 @@ export default async function Layout({ children }) {
async function RuntimePrefetchable() { async function RuntimePrefetchable() {
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-layout">{`Cookie from layout: ${cookieValue}`}</div> <div id="cookie-value-layout">{`Cookie from layout: ${cookieValue}`}</div>
......
...@@ -16,7 +16,7 @@ export default function Page() { ...@@ -16,7 +16,7 @@ export default function Page() {
async function RuntimePrefetchable() { async function RuntimePrefetchable() {
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div> <div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
......
...@@ -16,7 +16,7 @@ export default function Page() { ...@@ -16,7 +16,7 @@ export default function Page() {
async function RuntimePrefetchable() { async function RuntimePrefetchable() {
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div> <div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
......
...@@ -2,14 +2,13 @@ import { unstable_cacheLife } from 'next/cache' ...@@ -2,14 +2,13 @@ import { unstable_cacheLife } from 'next/cache'
import { setTimeout } from 'timers/promises' import { setTimeout } from 'timers/promises'
export async function uncachedIO() { export async function uncachedIO() {
await setTimeout(500) await setTimeout(0)
} }
export async function cachedDelay(time: number, cacheBuster?: any) { export async function cachedDelay(key: any) {
'use cache' 'use cache'
unstable_cacheLife('minutes') unstable_cacheLife('minutes')
console.log('cachedDelay', time, cacheBuster) await setTimeout(1)
await setTimeout(time)
} }
export function DebugRenderKind() { export function DebugRenderKind() {
......
...@@ -25,7 +25,7 @@ async function CachedButShortLived() { ...@@ -25,7 +25,7 @@ async function CachedButShortLived() {
// the rest of the settings don't matter for private caches, // the rest of the settings don't matter for private caches,
// because they are not persisted server-side // because they are not persisted server-side
}) })
await cachedDelay(500, [__filename]) await cachedDelay([__filename])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
......
...@@ -26,7 +26,7 @@ async function ShortLivedCache() { ...@@ -26,7 +26,7 @@ async function ShortLivedCache() {
revalidate: 2 * 60, revalidate: 2 * 60,
expire: 3 * 60, // < DYNAMIC_EXPIRE expire: 3 * 60, // < DYNAMIC_EXPIRE
}) })
await cachedDelay(500, [__filename]) await cachedDelay([__filename])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
......
...@@ -26,7 +26,7 @@ async function ShortLivedCache() { ...@@ -26,7 +26,7 @@ async function ShortLivedCache() {
revalidate: 2 * 60, revalidate: 2 * 60,
expire: 3 * 60, // < DYNAMIC_EXPIRE expire: 3 * 60, // < DYNAMIC_EXPIRE
}) })
await cachedDelay(500, [__filename]) await cachedDelay([__filename])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
......
...@@ -23,6 +23,6 @@ export default async function Page() { ...@@ -23,6 +23,6 @@ export default async function Page() {
async function One(): Promise<never> { async function One(): Promise<never> {
const cookieStore = await cookies() const cookieStore = await cookies()
await cachedDelay(500, ['/cookies', cookieStore.get('user-agent')?.value]) await cachedDelay(['/cookies', cookieStore.get('user-agent')?.value])
throw new Error('Kaboom') throw new Error('Kaboom')
} }
...@@ -20,6 +20,6 @@ export default async function Page() { ...@@ -20,6 +20,6 @@ export default async function Page() {
async function One() { async function One() {
const cookieStore = await cookies() const cookieStore = await cookies()
await cachedDelay(500, ['/cookies', cookieStore.get('user-agent')?.value]) await cachedDelay(['/cookies', cookieStore.get('user-agent')?.value])
return <div id="timestamp">Timestamp: {Date.now()}</div> return <div id="timestamp">Timestamp: {Date.now()}</div>
} }
...@@ -20,7 +20,7 @@ export default async function Page() { ...@@ -20,7 +20,7 @@ export default async function Page() {
async function RuntimePrefetchable() { async function RuntimePrefetchable() {
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value">{`Cookie: ${cookieValue}`}</div> <div id="cookie-value">{`Cookie: ${cookieValue}`}</div>
......
...@@ -34,7 +34,7 @@ export default async function Page() { ...@@ -34,7 +34,7 @@ export default async function Page() {
async function RuntimePrefetchable() { async function RuntimePrefetchable() {
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value">{`Cookie: ${cookieValue}`}</div> <div id="cookie-value">{`Cookie: ${cookieValue}`}</div>
......
...@@ -21,7 +21,7 @@ export default async function Page({ params }: { params: Promise<Params> }) { ...@@ -21,7 +21,7 @@ export default async function Page({ params }: { params: Promise<Params> }) {
async function RuntimePrefetchable({ params }: { params: Promise<Params> }) { async function RuntimePrefetchable({ params }: { params: Promise<Params> }) {
const { id } = await params const { id } = await params
await cachedDelay(500, [__filename, id]) await cachedDelay([__filename, id])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="param-value">{`Param: ${id}`}</div> <div id="param-value">{`Param: ${id}`}</div>
......
...@@ -29,7 +29,7 @@ async function RuntimePrefetchable({ ...@@ -29,7 +29,7 @@ async function RuntimePrefetchable({
searchParams: Promise<AnySearchParams> searchParams: Promise<AnySearchParams>
}) { }) {
const { searchParam } = await searchParams const { searchParam } = await searchParams
await cachedDelay(500, [__filename, searchParam]) await cachedDelay([__filename, searchParam])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="search-param-value">{`Search param: ${searchParam}`}</div> <div id="search-param-value">{`Search param: ${searchParam}`}</div>
......
...@@ -30,6 +30,6 @@ async function privateCache() { ...@@ -30,6 +30,6 @@ async function privateCache() {
'use cache: private' 'use cache: private'
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return cookieValue return cookieValue
} }
...@@ -47,7 +47,7 @@ async function privateCache() { ...@@ -47,7 +47,7 @@ async function privateCache() {
'use cache: private' 'use cache: private'
const cookieStore = await cookies() const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue]) await cachedDelay([__filename, cookieValue])
return cookieValue return cookieValue
} }
......
...@@ -32,7 +32,7 @@ async function RuntimePrefetchable() { ...@@ -32,7 +32,7 @@ async function RuntimePrefetchable() {
async function privateCache() { async function privateCache() {
'use cache: private' 'use cache: private'
const now = Date.now() const now = Date.now()
await cachedDelay(500, [__filename]) await cachedDelay([__filename])
return now return now
} }
......
...@@ -34,7 +34,7 @@ async function RuntimePrefetchable({ params }: { params: Promise<Params> }) { ...@@ -34,7 +34,7 @@ async function RuntimePrefetchable({ params }: { params: Promise<Params> }) {
async function privateCache(params: Promise<Params>) { async function privateCache(params: Promise<Params>) {
'use cache: private' 'use cache: private'
const { id } = await params const { id } = await params
await cachedDelay(500, [__filename, id]) await cachedDelay([__filename, id])
return id return id
} }
......
...@@ -42,7 +42,7 @@ async function RuntimePrefetchable({ ...@@ -42,7 +42,7 @@ async function RuntimePrefetchable({
async function privateCache(searchParams: Promise<AnySearchParams>) { async function privateCache(searchParams: Promise<AnySearchParams>) {
'use cache: private' 'use cache: private'
const { searchParam } = await searchParams const { searchParam } = await searchParams
await cachedDelay(500, [__filename, searchParam]) await cachedDelay([__filename, searchParam])
return searchParam return searchParam
} }
......
...@@ -2,14 +2,13 @@ import { unstable_cacheLife } from 'next/cache' ...@@ -2,14 +2,13 @@ import { unstable_cacheLife } from 'next/cache'
import { setTimeout } from 'timers/promises' import { setTimeout } from 'timers/promises'
export async function uncachedIO() { export async function uncachedIO() {
await setTimeout(500) await setTimeout(0)
} }
export async function cachedDelay(time: number, cacheBuster?: any) { export async function cachedDelay(key: any) {
'use cache' 'use cache'
unstable_cacheLife('minutes') unstable_cacheLife('minutes')
console.log('cachedDelay', time, cacheBuster) await setTimeout(1)
await setTimeout(time)
} }
export function DebugRenderKind() { export function DebugRenderKind() {
......
...@@ -19,7 +19,7 @@ export default async function Page() { ...@@ -19,7 +19,7 @@ export default async function Page() {
async function StaticallyPrefetchable() { async function StaticallyPrefetchable() {
const currentLang = await lang() const currentLang = await lang()
await cachedDelay(500, [__filename, currentLang]) await cachedDelay([__filename, currentLang])
return ( return (
<div style={{ border: '1px solid blue', padding: '1em' }}> <div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="root-param-value">{`Lang: ${currentLang}`}</div> <div id="root-param-value">{`Lang: ${currentLang}`}</div>
......
...@@ -35,7 +35,7 @@ async function DynamicallyPrefetchable() { ...@@ -35,7 +35,7 @@ async function DynamicallyPrefetchable() {
async function privateCache() { async function privateCache() {
'use cache: private' 'use cache: private'
const currentLang = await lang() const currentLang = await lang()
await cachedDelay(500, [__filename, currentLang]) await cachedDelay([__filename, currentLang])
return currentLang return currentLang
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment