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 }) {
async function RuntimePrefetchable() {
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-layout">{`Cookie from layout: ${cookieValue}`}</div>
......
......@@ -16,7 +16,7 @@ export default function Page() {
async function RuntimePrefetchable() {
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
......
......@@ -16,7 +16,7 @@ export default function Page() {
async function RuntimePrefetchable() {
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
......
......@@ -26,7 +26,7 @@ export default async function Layout({ children }) {
async function RuntimePrefetchable() {
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-layout">{`Cookie from layout: ${cookieValue}`}</div>
......
......@@ -16,7 +16,7 @@ export default function Page() {
async function RuntimePrefetchable() {
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
......
......@@ -16,7 +16,7 @@ export default function Page() {
async function RuntimePrefetchable() {
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value-page">{`Cookie from page: ${cookieValue}`}</div>
......
......@@ -2,14 +2,13 @@ import { unstable_cacheLife } from 'next/cache'
import { setTimeout } from 'timers/promises'
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'
unstable_cacheLife('minutes')
console.log('cachedDelay', time, cacheBuster)
await setTimeout(time)
await setTimeout(1)
}
export function DebugRenderKind() {
......
......@@ -25,7 +25,7 @@ async function CachedButShortLived() {
// the rest of the settings don't matter for private caches,
// because they are not persisted server-side
})
await cachedDelay(500, [__filename])
await cachedDelay([__filename])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
......
......@@ -26,7 +26,7 @@ async function ShortLivedCache() {
revalidate: 2 * 60,
expire: 3 * 60, // < DYNAMIC_EXPIRE
})
await cachedDelay(500, [__filename])
await cachedDelay([__filename])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
......
......@@ -26,7 +26,7 @@ async function ShortLivedCache() {
revalidate: 2 * 60,
expire: 3 * 60, // < DYNAMIC_EXPIRE
})
await cachedDelay(500, [__filename])
await cachedDelay([__filename])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
......
......@@ -23,6 +23,6 @@ export default async function Page() {
async function One(): Promise<never> {
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')
}
......@@ -20,6 +20,6 @@ export default async function Page() {
async function One() {
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>
}
......@@ -20,7 +20,7 @@ export default async function Page() {
async function RuntimePrefetchable() {
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value">{`Cookie: ${cookieValue}`}</div>
......
......@@ -34,7 +34,7 @@ export default async function Page() {
async function RuntimePrefetchable() {
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="cookie-value">{`Cookie: ${cookieValue}`}</div>
......
......@@ -21,7 +21,7 @@ export default async function Page({ params }: { params: Promise<Params> }) {
async function RuntimePrefetchable({ params }: { params: Promise<Params> }) {
const { id } = await params
await cachedDelay(500, [__filename, id])
await cachedDelay([__filename, id])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="param-value">{`Param: ${id}`}</div>
......
......@@ -29,7 +29,7 @@ async function RuntimePrefetchable({
searchParams: Promise<AnySearchParams>
}) {
const { searchParam } = await searchParams
await cachedDelay(500, [__filename, searchParam])
await cachedDelay([__filename, searchParam])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="search-param-value">{`Search param: ${searchParam}`}</div>
......
......@@ -30,6 +30,6 @@ async function privateCache() {
'use cache: private'
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return cookieValue
}
......@@ -47,7 +47,7 @@ async function privateCache() {
'use cache: private'
const cookieStore = await cookies()
const cookieValue = cookieStore.get('testCookie')?.value ?? null
await cachedDelay(500, [__filename, cookieValue])
await cachedDelay([__filename, cookieValue])
return cookieValue
}
......
......@@ -32,7 +32,7 @@ async function RuntimePrefetchable() {
async function privateCache() {
'use cache: private'
const now = Date.now()
await cachedDelay(500, [__filename])
await cachedDelay([__filename])
return now
}
......
......@@ -34,7 +34,7 @@ async function RuntimePrefetchable({ params }: { params: Promise<Params> }) {
async function privateCache(params: Promise<Params>) {
'use cache: private'
const { id } = await params
await cachedDelay(500, [__filename, id])
await cachedDelay([__filename, id])
return id
}
......
......@@ -42,7 +42,7 @@ async function RuntimePrefetchable({
async function privateCache(searchParams: Promise<AnySearchParams>) {
'use cache: private'
const { searchParam } = await searchParams
await cachedDelay(500, [__filename, searchParam])
await cachedDelay([__filename, searchParam])
return searchParam
}
......
......@@ -2,14 +2,13 @@ import { unstable_cacheLife } from 'next/cache'
import { setTimeout } from 'timers/promises'
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'
unstable_cacheLife('minutes')
console.log('cachedDelay', time, cacheBuster)
await setTimeout(time)
await setTimeout(1)
}
export function DebugRenderKind() {
......
......@@ -19,7 +19,7 @@ export default async function Page() {
async function StaticallyPrefetchable() {
const currentLang = await lang()
await cachedDelay(500, [__filename, currentLang])
await cachedDelay([__filename, currentLang])
return (
<div style={{ border: '1px solid blue', padding: '1em' }}>
<div id="root-param-value">{`Lang: ${currentLang}`}</div>
......
......@@ -35,7 +35,7 @@ async function DynamicallyPrefetchable() {
async function privateCache() {
'use cache: private'
const currentLang = await lang()
await cachedDelay(500, [__filename, currentLang])
await cachedDelay([__filename, 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