Unverified Commit 946d560a authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

test(turbopack): add polling to filesystem watcher fuzzer (#98863)

### What?

Adds an opt-in polling mode to the manual `turbo-tasks-fuzz fs-watcher`
stress harness through `--poll-interval-ms`.

Stack: **3/5** · Previous: #98983 · Next: #98737

### Why?

The fuzzer previously exercised only native filesystem events. A
configurable polling mode enables sustained stress testing of
PollWatcher invalidation behavior and provides a direct before/after
control for the notify upgrade in the next stack layer.

### How?

A positive, nonzero interval is mapped to
`DiskWatcherConfig.poll_interval`; omitting it preserves the
native-watcher defaults. The fuzzer passes an empty `DiskFileSystemMap`,
matching the default `DiskFileSystem::new` behavior while using the
extended constructor needed for watcher configuration.

Manual runs cover ordinary reads, tracked read-derived writes,
recursive/nonrecursive modes, directory recreation, and native omission.
CLI help also documents that notify's PollWatcher retains whole-second
mtime precision for non-files, so multiple symlink changes within one
second can be missed; this upstream limitation is reported rather than
hidden with timing workarounds.

<!-- NEXT_JS_LLM -->


<!-- fleet 6488265d-2685-49d3-b632-6511b4b47690 -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: 's avatarBenjamin Woodruff ‮ <180404+bgw@users.noreply.github.com>
parent 4ed2f4f3
...@@ -4,6 +4,7 @@ use std::{ ...@@ -4,6 +4,7 @@ use std::{
fs::OpenOptions, fs::OpenOptions,
io::{Read, Write}, io::{Read, Write},
iter, iter,
num::NonZeroU64,
path::{Path, PathBuf}, path::{Path, PathBuf},
sync::{Arc, Mutex}, sync::{Arc, Mutex},
time::Duration, time::Duration,
...@@ -19,7 +20,10 @@ use turbo_tasks::{ ...@@ -19,7 +20,10 @@ use turbo_tasks::{
read_strongly_consistent_and_apply_effects, take_effects, read_strongly_consistent_and_apply_effects, take_effects,
}; };
use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage}; use turbo_tasks_backend::{BackendOptions, TurboTasksBackend, noop_backing_storage};
use turbo_tasks_fs::{DiskFileSystem, File, FileContent, FileSystem, FileSystemPath}; use turbo_tasks_fs::{
DiskFileSystem, DiskFileSystemMap, DiskWatcherConfig, File, FileContent, FileSystem,
FileSystemPath,
};
// Prefix read-derived writes so they are idempotent: reading our own output produces the same // Prefix read-derived writes so they are idempotent: reading our own output produces the same
// effect value, while a subsequent external write produces a new one. // effect value, while a subsequent external write produces a new one.
...@@ -35,6 +39,10 @@ pub struct FsWatcher { ...@@ -35,6 +39,10 @@ pub struct FsWatcher {
width: usize, width: usize,
#[arg(long, default_value_t = 100)] #[arg(long, default_value_t = 100)]
notify_timeout_ms: u64, notify_timeout_ms: u64,
/// Poll the filesystem at this interval instead of using native events. Polling is slower, but
/// can be useful on filesystems where native events do not work.
#[arg(long, value_name = "MILLISECONDS")]
poll_interval_ms: Option<NonZeroU64>,
#[arg(long, default_value_t = 200)] #[arg(long, default_value_t = 200)]
file_modifications: u32, file_modifications: u32,
#[arg(long, default_value_t = 2)] #[arg(long, default_value_t = 2)]
...@@ -45,6 +53,8 @@ pub struct FsWatcher { ...@@ -45,6 +53,8 @@ pub struct FsWatcher {
#[arg(long)] #[arg(long)]
start_watching_late: bool, start_watching_late: bool,
/// Enable symlink testing. The mode controls what kind of targets the symlinks point to. /// Enable symlink testing. The mode controls what kind of targets the symlinks point to.
/// Polling may miss multiple symlink changes within one second because notify's PollWatcher
/// retains whole-second mtime precision for non-files.
#[arg(long, value_enum)] #[arg(long, value_enum)]
symlinks: Option<SymlinkMode>, symlinks: Option<SymlinkMode>,
/// Total number of symlinks to create. /// Total number of symlinks to create.
...@@ -95,10 +105,13 @@ pub async fn run(args: FsWatcher) -> anyhow::Result<()> { ...@@ -95,10 +105,13 @@ pub async fn run(args: FsWatcher) -> anyhow::Result<()> {
tt.run_once(async move { tt.run_once(async move {
let invalidations = TransientInstance::new(PathInvalidations::default()); let invalidations = TransientInstance::new(PathInvalidations::default());
let project_fs = disk_file_system_operation(RcStr::from(fs_root.to_str().unwrap())) let project_fs = disk_file_system_operation(
.resolve() RcStr::from(fs_root.to_str().unwrap()),
.strongly_consistent() watcher_config(args.poll_interval_ms),
.await?; )
.resolve()
.strongly_consistent()
.await?;
let project_root = disk_file_system_root_operation(project_fs) let project_root = disk_file_system_root_operation(project_fs)
.resolve() .resolve()
.strongly_consistent() .strongly_consistent()
...@@ -280,9 +293,25 @@ pub async fn run(args: FsWatcher) -> anyhow::Result<()> { ...@@ -280,9 +293,25 @@ pub async fn run(args: FsWatcher) -> anyhow::Result<()> {
.await .await
} }
fn watcher_config(poll_interval_ms: Option<NonZeroU64>) -> DiskWatcherConfig {
DiskWatcherConfig {
poll_interval: poll_interval_ms.map(|value| Duration::from_millis(value.get())),
..Default::default()
}
}
#[turbo_tasks::function(operation, root)] #[turbo_tasks::function(operation, root)]
fn disk_file_system_operation(fs_root: RcStr) -> Vc<DiskFileSystem> { fn disk_file_system_operation(
DiskFileSystem::new(rcstr!("project"), Vc::cell(fs_root)) fs_root: RcStr,
watcher_config: DiskWatcherConfig,
) -> Vc<DiskFileSystem> {
DiskFileSystem::new_with_options(
rcstr!("project"),
Vc::cell(fs_root),
Vec::new(),
watcher_config,
DiskFileSystemMap::empty(),
)
} }
#[turbo_tasks::function(operation, root)] #[turbo_tasks::function(operation, root)]
......
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