• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / tari / 16123384529

07 Jul 2025 05:11PM UTC coverage: 64.327% (-7.6%) from 71.89%
16123384529

push

github

web-flow
chore: new release v4.9.0-pre.0 (#7289)

Description
---
new release esmeralda

77151 of 119935 relevant lines covered (64.33%)

227108.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/infrastructure/test_utils/src/runtime.rs
1
// Copyright 2019, The Tari Project
2
//
3
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
// following conditions are met:
5
//
6
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
// disclaimer.
8
//
9
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
// following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
// products derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22

23
use std::{future::Future, pin::Pin};
24

25
use futures::{future, FutureExt};
26
use tari_shutdown::Shutdown;
27
use tokio::{runtime, runtime::Runtime, task, task::JoinError};
28

29
pub fn create_runtime() -> Runtime {
×
30
    tokio::runtime::Builder::new_multi_thread()
×
31
        .enable_all()
×
32
        .build()
×
33
        .expect("Could not create runtime")
×
34
}
×
35

36
pub fn spawn_until_shutdown<F>(fut: F) -> Shutdown
×
37
where F: Future<Output = ()> + Send + 'static {
×
38
    let shutdown = Shutdown::new();
×
39
    let signal = shutdown.to_signal();
×
40
    task::spawn(async move {
×
41
        futures::pin_mut!(fut);
×
42
        future::select(signal, fut).await;
×
43
    });
×
44
    shutdown
×
45
}
×
46

47
/// Create a runtime and report if it panics. If there are tasks still running after the panic, this
48
/// will carry on running forever.
49
// #[deprecated(note = "use tokio::test instead")]
50
pub fn test_async<F>(f: F)
×
51
where F: FnOnce(&mut TestRuntime) {
×
52
    let mut rt = TestRuntime::from(create_runtime());
×
53
    f(&mut rt);
×
54
    let handles = rt.handles.drain(..).collect::<Vec<_>>();
×
55
    for h in handles {
×
56
        rt.block_on(h).unwrap();
×
57
    }
×
58
}
×
59

60
type BoxedJoinFuture = Pin<Box<dyn Future<Output = Result<(), JoinError>>>>;
61

62
pub struct TestRuntime {
63
    inner: Runtime,
64
    handles: Vec<BoxedJoinFuture>,
65
}
66

67
impl TestRuntime {
68
    pub fn block_on<F: Future>(&mut self, future: F) -> F::Output {
×
69
        self.inner.block_on(future)
×
70
    }
×
71

72
    pub fn spawn<F>(&mut self, future: F)
×
73
    where
×
74
        F: Future + Send + 'static,
×
75
        F::Output: Send + 'static,
×
76
    {
×
77
        let handle = self.inner.spawn(future);
×
78
        self.handles.push(
×
79
            handle
×
80
                .map(|result| match result {
×
81
                    Ok(_) => Ok(()),
×
82
                    Err(err) => Err(err),
×
83
                })
×
84
                .boxed(),
×
85
        );
×
86
    }
×
87

88
    pub fn spawn_unchecked<F>(&mut self, future: F) -> task::JoinHandle<F::Output>
×
89
    where
×
90
        F: Future + Send + 'static,
×
91
        F::Output: Send + 'static,
×
92
    {
×
93
        self.inner.spawn(future)
×
94
    }
×
95

96
    pub fn handle(&self) -> &runtime::Handle {
×
97
        self.inner.handle()
×
98
    }
×
99
}
100

101
impl From<Runtime> for TestRuntime {
102
    fn from(rt: Runtime) -> Self {
×
103
        Self {
×
104
            inner: rt,
×
105
            handles: Vec::new(),
×
106
        }
×
107
    }
×
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc