stress_test/environment.rs
1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::actor_runner::ActorRunner;
6use async_trait::async_trait;
7use std::fmt::Debug;
8
9/// Every stress test must implement this trait exactly once and pass it
10/// to run_test(). The test loop uses these methods to drive the stress test.
11///
12/// The environment is responsible for:
13/// * creating actors that run during the stress test
14/// * creating a new instance when an actor requests one
15/// * specifying success criteria for the test (num operations or timeout)
16#[async_trait]
17pub trait Environment: Send + Sync + Debug {
18 /// Returns the target number of operations to complete before exiting
19 fn target_operations(&self) -> Option<u64>;
20
21 /// Returns the number of seconds to wait before exiting
22 fn timeout_seconds(&self) -> Option<u64>;
23
24 /// Return the runners for all the actors
25 async fn actor_runners(&mut self) -> Vec<ActorRunner>;
26
27 /// Reset the environment, when an actor requests one
28 async fn reset(&mut self);
29
30 /// An optional hook to invoke when panicking. Can be used to dump additional state.
31 /// No reference to &self is taken by the function to make it feasible to invoke this hook while
32 /// a &mut exists on the Environment. Since this is invoked during panic, the function should
33 /// avoid blocking on locks or other resources.
34 fn panic_hook(&self) -> Option<Box<dyn Fn() + 'static + Sync + Send>> {
35 None
36 }
37}