Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
7fb1093d
Commit
7fb1093d
authored
Nov 10, 2025
by
Luke Sandberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Run the filesystem caching test with and without caching enabled.
parent
a70575fc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
105 additions
and
76 deletions
+105
-76
filesystem-cache.test.ts
test/e2e/filesystem-cache/filesystem-cache.test.ts
+83
-68
next.config.js
test/e2e/filesystem-cache/next.config.js
+7
-2
mod.rs
turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
+15
-6
No files found.
test/e2e/filesystem-cache/filesystem-cache.ts
→
test/e2e/filesystem-cache/filesystem-cache.t
est.t
s
View file @
7fb1093d
import
{
nextTestSetup
,
isNextDev
}
from
'e2e-utils'
import
{
waitFor
}
from
'next-test-utils'
describe
(
'
persistent
-caching'
,
()
=>
{
describe
(
'
filesystem
-caching'
,
()
=>
{
process
.
env
.
NEXT_PUBLIC_ENV_VAR
=
'hello world'
// Make it easier to run in development, test directories are cleared between runs already so this is safe.
process
.
env
.
TURBO_ENGINE_DISABLE_VERSIONING
=
'1'
// decrease the idle timeout to make the test more reliable
process
.
env
.
TURBO_ENGINE_SNAPSHOT_IDLE_TIMEOUT_MILLIS
=
'1000'
const
{
skipped
,
next
,
isTurbopack
}
=
nextTestSetup
({
files
:
__dirname
,
skipDeployment
:
true
,
...
...
@@ -30,7 +34,7 @@ describe('persistent-caching', () => {
async
function
stop
()
{
if
(
isNextDev
)
{
// Give FileSystem Cache time to write to disk
// Turbopack
has an idle timeout of 2s
// Turbopack
is conffigured to wait 1s above.
// Webpack has an idle timeout (after large changes) of 1s
// and we give time a bit more to allow writing to disk
await
waitFor
(
3000
)
...
...
@@ -43,6 +47,7 @@ describe('persistent-caching', () => {
}
it
(
'should filesystem cache loaders'
,
async
()
=>
{
process
.
env
.
ENABLE_CACHING
=
'1'
let
appTimestamp
,
unchangedTimestamp
,
appClientTimestamp
,
pagesTimestamp
{
const
browser
=
await
next
.
browser
(
'/'
)
...
...
@@ -114,7 +119,13 @@ describe('persistent-caching', () => {
}
}
const
POTENTIAL_CHANGES
=
{
interface
Change
{
checkInitial
():
Promise
<
void
>
withChange
(
previous
:
()
=>
Promise
<
void
>
):
Promise
<
void
>
checkChanged
():
Promise
<
void
>
fullInvalidation
?:
boolean
}
const
POTENTIAL_CHANGES
:
Record
<
string
,
Change
>
=
{
'RSC change'
:
{
checkInitial
:
makeTextCheck
(
'/'
,
'hello world'
),
withChange
:
makeFileEdit
(
'app/page.tsx'
),
...
...
@@ -189,80 +200,84 @@ describe('persistent-caching', () => {
await
textCheck
(
'/env/client'
,
'hello filesystem cache'
)
},
},
}
}
as
const
const
KEYS
=
Object
.
keys
(
POTENTIAL_CHANGES
)
for
(
let
bitset
=
1
;
bitset
<
1
<<
KEYS
.
length
;
bitset
++
)
{
let
combination
=
[]
for
(
let
i
=
0
;
i
<
KEYS
.
length
;
i
++
)
{
if
(
bitset
&
(
1
<<
i
))
{
combination
.
push
(
KEYS
[
i
])
}
}
// Checking only single change and all combined for performance reasons.
if
(
combination
.
length
!==
1
&&
combination
.
length
!==
KEYS
.
length
)
continue
// Checking only single change and all combined for performance reasons.
const
combinations
=
Object
.
entries
(
POTENTIAL_CHANGES
).
map
(([
k
,
v
])
=>
[
k
,
[
v
],
])
as
Array
<
[
string
,
Array
<
Change
>
]
>
combinations
.
push
([
Object
.
keys
(
POTENTIAL_CHANGES
).
join
(
', '
),
Object
.
values
(
POTENTIAL_CHANGES
),
])
for
(
const
cacheEnabled
of
[
true
,
false
])
{
process
.
env
.
ENABLE_CACHING
=
cacheEnabled
?
'1'
:
'0'
describe
(
`with cache
${
cacheEnabled
?
'enabled'
:
'disabled'
}
`
,
()
=>
{
for
(
const
[
name
,
changes
]
of
combinations
)
{
it
(
`should allow to change files while stopped (
${
name
}
)`
,
async
()
=>
{
let
fullInvalidation
=
false
for
(
const
change
of
changes
)
{
await
change
.
checkInitial
()
if
(
change
.
fullInvalidation
)
{
fullInvalidation
=
true
}
}
it
(
`should allow to change files while stopped (
${
combination
.
join
(
', '
)}
)`
,
async
()
=>
{
let
fullInvalidation
=
false
for
(
const
key
of
combination
)
{
await
POTENTIAL_CHANGES
[
key
].
checkInitial
()
if
(
POTENTIAL_CHANGES
[
key
].
fullInvalidation
)
{
fullInvalidation
=
true
}
}
let
unchangedTimestamp
:
string
if
(
!
fullInvalidation
)
{
const
browser
=
await
next
.
browser
(
'/unchanged'
)
unchangedTimestamp
=
await
browser
.
elementByCss
(
'main'
).
text
()
expect
(
unchangedTimestamp
).
toMatch
(
/Timestamp =
\d
+$/
)
await
browser
.
close
()
}
let
unchangedTimestamp
if
(
!
fullInvalidation
)
{
const
browser
=
await
next
.
browser
(
'/unchanged'
)
unchangedTimestamp
=
await
browser
.
elementByCss
(
'main'
).
text
()
expect
(
unchangedTimestamp
).
toMatch
(
/Timestamp =
\d
+$/
)
await
browser
.
close
()
}
async
function
checkChanged
()
{
for
(
const
change
of
changes
)
{
await
change
.
checkChanged
()
}
async
function
checkChanged
()
{
for
(
const
key
of
combination
)
{
await
POTENTIAL_CHANGES
[
key
].
checkChanged
()
}
if
(
!
fullInvalidation
)
{
const
browser
=
await
next
.
browser
(
'/unchanged'
)
const
timestamp
=
await
browser
.
elementByCss
(
'main'
).
text
()
expect
(
unchangedTimestamp
).
toEqual
(
timestamp
)
await
browser
.
close
()
}
}
if
(
!
fullInvalidation
)
{
const
browser
=
await
next
.
browser
(
'/unchanged'
)
const
timestamp
=
await
browser
.
elementByCss
(
'main'
).
text
()
expect
(
unchangedTimestamp
).
toEqual
(
timestamp
)
await
browser
.
close
()
}
}
await
stop
()
await
stop
()
async
function
inner
()
{
await
start
()
await
checkChanged
()
// Some no-op change builds
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
await
restartCycle
()
await
checkChanged
()
}
await
stop
()
}
async
function
inner
()
{
await
start
()
await
checkChanged
()
// Some no-op change builds
for
(
let
i
=
0
;
i
<
2
;
i
++
)
{
await
restartCycle
()
await
checkChanged
()
}
await
stop
()
}
let
current
=
inner
for
(
const
change
of
changes
)
{
const
prev
=
current
current
=
()
=>
change
.
withChange
(
prev
)
}
await
current
()
let
current
=
inner
for
(
const
key
of
combination
)
{
const
prev
=
current
current
=
()
=>
POTENTIAL_CHANGES
[
key
].
withChange
(
prev
)
}
await
current
()
await
start
()
for
(
const
key
of
combination
)
{
await
POTENTIAL_CHANGES
[
key
].
checkInitial
()
}
await
start
()
for
(
const
change
of
changes
)
{
await
change
.
checkInitial
()
}
if
(
!
fullInvalidation
)
{
const
browser
=
await
next
.
browser
(
'/unchanged'
)
const
timestamp
=
await
browser
.
elementByCss
(
'main'
).
text
()
expect
(
unchangedTimestamp
).
toEqual
(
timestamp
)
await
browser
.
close
()
if
(
!
fullInvalidation
)
{
const
browser
=
await
next
.
browser
(
'/unchanged'
)
const
timestamp
=
await
browser
.
elementByCss
(
'main'
).
text
()
expect
(
unchangedTimestamp
).
toEqual
(
timestamp
)
await
browser
.
close
()
}
},
200000
)
}
}
,
200000
)
})
}
})
test/e2e/filesystem-cache/next.config.js
View file @
7fb1093d
const
enableCaching
=
!!
process
.
env
.
ENABLE_CACHING
/**
* @type {import('next').NextConfig}
*/
...
...
@@ -16,8 +18,8 @@ const nextConfig = {
},
},
experimental
:
{
turbopackFileSystemCacheForDev
:
true
,
turbopackFileSystemCacheForBuild
:
true
,
turbopackFileSystemCacheForDev
:
enableCaching
,
turbopackFileSystemCacheForBuild
:
enableCaching
,
},
env
:
{
NEXT_PUBLIC_CONFIG_ENV
:
'hello world'
,
...
...
@@ -31,6 +33,9 @@ const nextConfig = {
test
:
/app
\/
loader
(?:\/
client
)?\/
page
\.
tsx/
,
use
:
[
'./my-loader.js'
],
})
config
.
cache
=
Object
.
freeze
({
type
:
enableCaching
?
'filesystem'
:
'memory'
,
})
if
(
dev
)
{
// Make webpack consider the build as large change which makes it filesystem cache it sooner
config
.
plugins
.
push
((
compiler
)
=>
{
...
...
turbopack/crates/turbo-tasks-backend/src/backend/mod.rs
View file @
7fb1093d
...
...
@@ -12,7 +12,7 @@ use std::{
ops
::
Range
,
pin
::
Pin
,
sync
::{
Arc
,
Arc
,
LazyLock
,
atomic
::{
AtomicBool
,
AtomicU64
,
AtomicUsize
,
Ordering
},
},
};
...
...
@@ -72,6 +72,16 @@ use crate::{
const
SNAPSHOT_REQUESTED_BIT
:
usize
=
1
<<
(
usize
::
BITS
-
1
);
/// Configurable idle timeout for snapshot persistence.
/// Defaults to 2 seconds if not set or if the value is invalid.
static
IDLE_TIMEOUT
:
LazyLock
<
Duration
>
=
LazyLock
::
new
(||
{
std
::
env
::
var
(
"TURBO_ENGINE_SNAPSHOT_IDLE_TIMEOUT_MILLIS"
)
.ok
()
.and_then
(|
v
|
v
.parse
::
<
u64
>
()
.ok
())
.map
(
Duration
::
from_millis
)
.unwrap_or
(
Duration
::
from_secs
(
2
))
});
struct
SnapshotRequest
{
snapshot_requested
:
bool
,
suspended_operations
:
FxHashSet
<
PtrEqArc
<
AnyOperation
>>
,
...
...
@@ -2421,8 +2431,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
loop
{
const
FIRST_SNAPSHOT_WAIT
:
Duration
=
Duration
::
from_secs
(
300
);
const
SNAPSHOT_INTERVAL
:
Duration
=
Duration
::
from_secs
(
120
);
const
IDLE_TIMEOUT
:
Duration
=
Duration
::
from_secs
(
2
);
let
idle_timeout
=
*
IDLE_TIMEOUT
;
let
(
time
,
mut
reason
)
=
if
matches!
(
job
,
TurboTasksBackendJob
::
InitialSnapshot
)
{
(
FIRST_SNAPSHOT_WAIT
,
"initial snapshot timeout"
)
...
...
@@ -2439,7 +2448,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
let
mut
idle_start_listener
=
self
.idle_start_event
.listen
();
let
mut
idle_end_listener
=
self
.idle_end_event
.listen
();
let
mut
idle_time
=
if
turbo_tasks
.is_idle
()
{
Instant
::
now
()
+
IDLE_TIMEOUT
Instant
::
now
()
+
idle_timeout
}
else
{
far_future
()
};
...
...
@@ -2449,11 +2458,11 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
return
;
},
_
=
&
mut
idle_start_listener
=>
{
idle_time
=
Instant
::
now
()
+
IDLE_TIMEOUT
;
idle_time
=
Instant
::
now
()
+
idle_timeout
;
idle_start_listener
=
self
.idle_start_event
.listen
()
},
_
=
&
mut
idle_end_listener
=>
{
idle_time
=
until
+
IDLE_TIMEOUT
;
idle_time
=
until
+
idle_timeout
;
idle_end_listener
=
self
.idle_end_event
.listen
()
},
_
=
tokio
::
time
::
sleep_until
(
until
)
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment