diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-02-23 11:11:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-23 11:11:15 -0700 |
commit | 5193834cf23e3521b3afd3f5f54eb00daa23c88d (patch) | |
tree | d67bcef4d96f615f345ad1679d27d73bdc2ccd39 /ext/io/lib.rs | |
parent | 619acce305ac77f98327718bc1e6a1ae13d8bcf6 (diff) |
refactor(cli): clean up test runner channels (#22422)
Gets us closer to solving #20707.
Rewrites the `TestEventSender`:
- Allow for explicit creation of multiple streams. This will allow for
one-std{out,err}-per-worker
- All test events are received along with a worker ID, allowing for
eventual, proper parallel threading of test events.
In theory this should open up proper interleaving of test output,
however that is left for a future PR.
I had some plans for a better performing synchronization primitive, but
the inter-thread communication is tricky. This does, however, speed up
the processing of large numbers of tests 15-25% (possibly even more on
100,000+).
Before
```
ok | 1000 passed | 0 failed (32ms)
ok | 10000 passed | 0 failed (276ms)
```
After
```
ok | 1000 passed | 0 failed (25ms)
ok | 10000 passed | 0 failed (230ms)
```
Diffstat (limited to 'ext/io/lib.rs')
-rw-r--r-- | ext/io/lib.rs | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/ext/io/lib.rs b/ext/io/lib.rs index e0d649e0a..8d80eec25 100644 --- a/ext/io/lib.rs +++ b/ext/io/lib.rs @@ -110,36 +110,36 @@ deno_core::extension!(deno_io, let t = &mut state.resource_table; let rid = t.add(fs::FileResource::new( - Rc::new(match stdio.stdin { - StdioPipe::Inherit => StdFileResourceInner::new( + Rc::new(match stdio.stdin.pipe { + StdioPipeInner::Inherit => StdFileResourceInner::new( StdFileResourceKind::Stdin, STDIN_HANDLE.try_clone().unwrap(), ), - StdioPipe::File(pipe) => StdFileResourceInner::file(pipe), + StdioPipeInner::File(pipe) => StdFileResourceInner::file(pipe), }), "stdin".to_string(), )); assert_eq!(rid, 0, "stdin must have ResourceId 0"); let rid = t.add(FileResource::new( - Rc::new(match stdio.stdout { - StdioPipe::Inherit => StdFileResourceInner::new( + Rc::new(match stdio.stdout.pipe { + StdioPipeInner::Inherit => StdFileResourceInner::new( StdFileResourceKind::Stdout, STDOUT_HANDLE.try_clone().unwrap(), ), - StdioPipe::File(pipe) => StdFileResourceInner::file(pipe), + StdioPipeInner::File(pipe) => StdFileResourceInner::file(pipe), }), "stdout".to_string(), )); assert_eq!(rid, 1, "stdout must have ResourceId 1"); let rid = t.add(FileResource::new( - Rc::new(match stdio.stderr { - StdioPipe::Inherit => StdFileResourceInner::new( + Rc::new(match stdio.stderr.pipe { + StdioPipeInner::Inherit => StdFileResourceInner::new( StdFileResourceKind::Stderr, STDERR_HANDLE.try_clone().unwrap(), ), - StdioPipe::File(pipe) => StdFileResourceInner::file(pipe), + StdioPipeInner::File(pipe) => StdFileResourceInner::file(pipe), }), "stderr".to_string(), )); @@ -148,22 +148,41 @@ deno_core::extension!(deno_io, }, ); -pub enum StdioPipe { - Inherit, - File(StdFile), +#[derive(Default)] +pub struct StdioPipe { + pipe: StdioPipeInner, } -impl Default for StdioPipe { - fn default() -> Self { - Self::Inherit +impl StdioPipe { + pub const fn inherit() -> Self { + StdioPipe { + pipe: StdioPipeInner::Inherit, + } + } + + pub fn file(f: impl Into<StdFile>) -> Self { + StdioPipe { + pipe: StdioPipeInner::File(f.into()), + } } } +#[derive(Default)] +enum StdioPipeInner { + #[default] + Inherit, + File(StdFile), +} + impl Clone for StdioPipe { fn clone(&self) -> Self { - match self { - StdioPipe::Inherit => StdioPipe::Inherit, - StdioPipe::File(pipe) => StdioPipe::File(pipe.try_clone().unwrap()), + match &self.pipe { + StdioPipeInner::Inherit => Self { + pipe: StdioPipeInner::Inherit, + }, + StdioPipeInner::File(pipe) => Self { + pipe: StdioPipeInner::File(pipe.try_clone().unwrap()), + }, } } } |