Skip to main content

run_test_suite_lib/
connector.rs

1// Copyright 2022 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::outcome::ConnectionError;
6use flex_fuchsia_test_manager::SuiteRunnerProxy;
7use futures::lock::Mutex;
8use std::future::Future;
9
10/// Implementing this trait allows configuring the number of suites to
11/// run on a single SuiteRunner connection.
12/// This alleviates an issue where for n suites run on a single SuiteRunner
13/// connection, n channels must be opened up front. This can cause some
14/// issues with resource limitations when a large number of tests is
15/// specified (see https://fxbug.dev/42062444).
16pub trait SuiteRunnerConnector {
17    /// Create a new connection to SuiteRunner.
18    fn connect(&self) -> impl Future<Output = Result<SuiteRunnerProxy, ConnectionError>> + Send;
19    /// Number of suites for which a connection produced by this connector
20    /// should be used.
21    fn batch_size(&self) -> usize;
22}
23
24/// A connector that produces a single proxy and instructs all suites to
25/// be executed using it.
26pub struct SingleRunConnector {
27    proxy: Mutex<Option<SuiteRunnerProxy>>,
28}
29
30impl SingleRunConnector {
31    pub fn new(proxy: SuiteRunnerProxy) -> Self {
32        Self { proxy: Mutex::new(Some(proxy)) }
33    }
34}
35
36impl SuiteRunnerConnector for SingleRunConnector {
37    async fn connect(&self) -> Result<SuiteRunnerProxy, ConnectionError> {
38        Ok(self.proxy.lock().await.take().expect("connect only called once"))
39    }
40
41    fn batch_size(&self) -> usize {
42        usize::MAX
43    }
44}