()
| 42 | |
| 43 | #[test_log::test(tokio::test(flavor = "multi_thread"))] |
| 44 | async fn p2_api_time() -> Result<()> { |
| 45 | struct FakeWallClock; |
| 46 | |
| 47 | impl HostWallClock for FakeWallClock { |
| 48 | fn resolution(&self) -> Duration { |
| 49 | Duration::from_secs(1) |
| 50 | } |
| 51 | |
| 52 | fn now(&self) -> Duration { |
| 53 | Duration::new(1431648000, 100) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | struct FakeMonotonicClock { |
| 58 | now: Mutex<u64>, |
| 59 | } |
| 60 | |
| 61 | impl HostMonotonicClock for FakeMonotonicClock { |
| 62 | fn resolution(&self) -> u64 { |
| 63 | 1_000_000_000 |
| 64 | } |
| 65 | |
| 66 | fn now(&self) -> u64 { |
| 67 | let mut now = self.now.lock().unwrap(); |
| 68 | let then = *now; |
| 69 | *now += 42 * 1_000_000_000; |
| 70 | then |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | let table = ResourceTable::new(); |
| 75 | let wasi = WasiCtxBuilder::new() |
| 76 | .monotonic_clock(FakeMonotonicClock { now: Mutex::new(0) }) |
| 77 | .wall_clock(FakeWallClock) |
| 78 | .build(); |
| 79 | |
| 80 | let (mut store, command) = |
| 81 | instantiate(P2_API_TIME_COMPONENT, CommandCtx { table, wasi }).await?; |
| 82 | |
| 83 | command |
| 84 | .wasi_cli_run() |
| 85 | .call_run(&mut store) |
| 86 | .await? |
| 87 | .map_err(|()| wasmtime::format_err!("command returned with failing exit status")) |
| 88 | } |
| 89 | |
| 90 | #[test_log::test(tokio::test(flavor = "multi_thread"))] |
| 91 | async fn p2_api_read_only() -> Result<()> { |
nothing calls this directly
no test coverage detected