diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-03-14 19:17:52 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-15 10:58:18 -0400 |
commit | 1811318097b57c136913bd95bb9e16d820cc1a1a (patch) | |
tree | 1459444a37d4ea961d1b1f1da2cd0044ed2c5ac9 /core/test_util.rs | |
parent | 76c73ec61ec4271581795a2f0e3ae60072676dae (diff) |
core: Behavior shouldn't be generic
We always pass around Box<[u8]>, and adding this generic is an
unnecessary complication.
Add deno_core_http_bench_test to test.py
sharedQueue works on deno_core_http_bench
Diffstat (limited to 'core/test_util.rs')
-rw-r--r-- | core/test_util.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/test_util.rs b/core/test_util.rs new file mode 100644 index 000000000..80025c2be --- /dev/null +++ b/core/test_util.rs @@ -0,0 +1,51 @@ +use crate::isolate::Behavior; +use crate::isolate::Op; +use crate::libdeno::deno_buf; +use crate::libdeno::deno_mod; +use std::collections::HashMap; + +pub struct TestBehavior { + pub dispatch_count: usize, + pub resolve_count: usize, + pub mod_map: HashMap<String, deno_mod>, +} + +impl TestBehavior { + pub fn new() -> Self { + Self { + dispatch_count: 0, + resolve_count: 0, + mod_map: HashMap::new(), + } + } + + pub fn register(&mut self, name: &str, id: deno_mod) { + self.mod_map.insert(name.to_string(), id); + } +} + +impl Behavior for TestBehavior { + fn startup_snapshot(&mut self) -> Option<deno_buf> { + None + } + + fn dispatch( + &mut self, + control: &[u8], + _zero_copy_buf: deno_buf, + ) -> (bool, Box<Op>) { + assert_eq!(control.len(), 1); + assert_eq!(control[0], 42); + self.dispatch_count += 1; + let buf = vec![43u8].into_boxed_slice(); + (false, Box::new(futures::future::ok(buf))) + } + + fn resolve(&mut self, specifier: &str, _referrer: deno_mod) -> deno_mod { + self.resolve_count += 1; + match self.mod_map.get(specifier) { + Some(id) => *id, + None => 0, + } + } +} |