The same as `fuzz` but `async`.
(&self, test_func: impl AsyncFn() -> Result<()>)
| 348 | |
| 349 | /// The same as `fuzz` but `async`. |
| 350 | pub async fn fuzz_async(&self, test_func: impl AsyncFn() -> Result<()>) -> Result<()> { |
| 351 | let max_iters = match self.max_iters { |
| 352 | Some(n) => n, |
| 353 | None => bail!("OomTest::fuzz requires max_iters to be set"), |
| 354 | }; |
| 355 | |
| 356 | let total_allocs = Self::count_allocations(&test_func).await?; |
| 357 | |
| 358 | if total_allocs == 0 { |
| 359 | return Ok(()); |
| 360 | } |
| 361 | |
| 362 | let mut rng = SmallRng::seed_from_u64(self.seed); |
| 363 | |
| 364 | for _ in 0..max_iters { |
| 365 | let i = rng.random_range(0..total_allocs); |
| 366 | log::trace!("=== Injecting OOM after {i} allocations (fuzz) ==="); |
| 367 | self.run_one_oom_injection(&test_func, i).await?; |
| 368 | } |
| 369 | |
| 370 | Ok(()) |
| 371 | } |
| 372 | |
| 373 | /// Run the test function once, injecting OOM on the `i`th allocation, and |
| 374 | /// check that the result correctly reflects whether an OOM was hit. |