Skip to content

Commit 3b87be0

Browse files
committed
Merge pull-request #583
2 parents c25ca91 + 81626d7 commit 3b87be0

File tree

10 files changed

+128
-127
lines changed

10 files changed

+128
-127
lines changed

src/init/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async fn main() {
8383
)
8484
.expect("unable to create app pool");
8585

86-
Reaper::execute(&handles, Box::new(Nsm), core_pool, app_pool, None);
86+
Reaper::execute(&handles, Box::new(Nsm), core_pool, app_pool, None).await;
8787

8888
reboot();
8989
}

src/integration/examples/boot_enclave.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ async fn main() {
437437
}
438438

439439
// Give the enclave time to start the pivot
440-
std::thread::sleep(std::time::Duration::from_secs(2));
440+
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
441441

442442
let enclave_info_url =
443443
format!("http://{LOCAL_HOST}:{}/qos/enclave-info", host_port);

src/integration/src/bin/pivot_socket_stress.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Processor {
2121
impl RequestProcessor for Processor {
2222
async fn process(&self, request: &[u8]) -> Vec<u8> {
2323
// Simulate just some baseline lag for all requests
24-
std::thread::sleep(std::time::Duration::from_secs(1));
24+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
2525

2626
let msg = PivotSocketStressMsg::try_from_slice(request)
2727
.expect("Received invalid message - test is broken");

src/integration/tests/boot.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,18 +445,18 @@ async fn standard_boot_e2e() {
445445
.success());
446446
}
447447

448-
// Give the enclave time to start the pivot
449-
std::thread::sleep(std::time::Duration::from_secs(2));
450-
451-
// Check that the pivot executed
452-
let contents = std::fs::read(PIVOT_OK2_SUCCESS_FILE).unwrap();
453-
assert_eq!(std::str::from_utf8(&contents).unwrap(), msg);
454-
455448
let enclave_info_url =
456449
format!("http://{LOCAL_HOST}:{}/qos/enclave-info", host_port);
457450
let enclave_info: EnclaveInfo =
458451
ureq::get(&enclave_info_url).call().unwrap().into_json().unwrap();
459452
assert_eq!(enclave_info.phase, ProtocolPhase::QuorumKeyProvisioned);
460453

454+
// Give the enclave time to start the pivot
455+
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
456+
457+
// Check that the pivot executed
458+
let contents = std::fs::read(PIVOT_OK2_SUCCESS_FILE).unwrap();
459+
assert_eq!(std::str::from_utf8(&contents).unwrap(), msg);
460+
461461
fs::remove_file(PIVOT_OK2_SUCCESS_FILE).unwrap();
462462
}

src/integration/tests/dev_boot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async fn dev_boot_e2e() {
7777
.unwrap();
7878

7979
// Give the coordinator time to pivot
80-
std::thread::sleep(std::time::Duration::from_secs(2));
80+
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
8181

8282
// Make sure pivot ran
8383
assert!(Path::new(PIVOT_OK3_SUCCESS_FILE).exists());

src/integration/tests/enclave_app_client_socket_stress.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::time::Duration;
2+
13
use borsh::BorshDeserialize;
24
use integration::{
35
wait_for_usock, PivotSocketStressMsg, PIVOT_SOCKET_STRESS_PATH,
@@ -14,7 +16,7 @@ use qos_core::{
1416
},
1517
ProtocolError, ProtocolPhase, ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS,
1618
},
17-
reaper::{Reaper, REAPER_RESTART_DELAY_IN_SECONDS},
19+
reaper::{Reaper, REAPER_RESTART_DELAY},
1820
};
1921
use qos_nsm::mock::MockNsm;
2022
use qos_p256::P256Pair;
@@ -76,12 +78,12 @@ async fn enclave_app_client_socket_stress() {
7678
handles.put_quorum_key(&p256_pair).unwrap();
7779

7880
let enclave_pool =
79-
StreamPool::new(SocketAddress::new_unix(ENCLAVE_SOCK), 1).unwrap();
81+
StreamPool::single(SocketAddress::new_unix(ENCLAVE_SOCK)).unwrap();
8082

8183
let app_pool =
82-
StreamPool::new(SocketAddress::new_unix(APP_SOCK), 1).unwrap();
84+
StreamPool::single(SocketAddress::new_unix(APP_SOCK)).unwrap();
8385

84-
std::thread::spawn(move || {
86+
tokio::spawn(async move {
8587
Reaper::execute(
8688
&handles,
8789
Box::new(MockNsm),
@@ -91,13 +93,14 @@ async fn enclave_app_client_socket_stress() {
9193
// works
9294
Some(ProtocolPhase::QuorumKeyProvisioned),
9395
)
96+
.await;
9497
});
9598

9699
// Make sure the pivot has some time to start up
97100
wait_for_usock(APP_SOCK).await;
98101

99102
let enclave_client_pool =
100-
StreamPool::new(SocketAddress::new_unix(ENCLAVE_SOCK), 1).unwrap();
103+
StreamPool::single(SocketAddress::new_unix(ENCLAVE_SOCK)).unwrap();
101104
let enclave_client = SocketClient::new(
102105
enclave_client_pool.shared(),
103106
TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS + 3), // needs to be bigger than the slow request below + some time for recovery
@@ -118,10 +121,7 @@ async fn enclave_app_client_socket_stress() {
118121
)
119122
);
120123

121-
tokio::time::sleep(std::time::Duration::from_secs(
122-
REAPER_RESTART_DELAY_IN_SECONDS + 1,
123-
))
124-
.await;
124+
tokio::time::sleep(REAPER_RESTART_DELAY + Duration::from_secs(1)).await;
125125
// The pivot panicked and should have been restarted.
126126
let app_request =
127127
borsh::to_vec(&PivotSocketStressMsg::OkRequest(1)).unwrap();

src/integration/tests/reaper.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use qos_core::{
55
handles::Handles,
66
io::{SocketAddress, StreamPool},
77
protocol::services::boot::ManifestEnvelope,
8-
reaper::{Reaper, REAPER_EXIT_DELAY_IN_SECONDS},
8+
reaper::{Reaper, REAPER_EXIT_DELAY},
99
};
1010
use qos_nsm::mock::MockNsm;
1111
use qos_test_primitives::PathWrapper;
1212

13-
#[test]
14-
fn reaper_works() {
13+
#[tokio::test]
14+
async fn reaper_works() {
1515
let secret_path: PathWrapper = "/tmp/reaper_works.secret".into();
1616
// let eph_path = "reaper_works.eph.key";
1717
let usock: PathWrapper = "/tmp/reaper_works.sock".into();
@@ -43,18 +43,19 @@ fn reaper_works() {
4343
let app_pool =
4444
StreamPool::new(SocketAddress::new_unix("./never.sock"), 1).unwrap();
4545

46-
let reaper_handle = std::thread::spawn(move || {
46+
let reaper_handle = tokio::spawn(async move {
4747
Reaper::execute(
4848
&handles,
4949
Box::new(MockNsm),
5050
enclave_pool,
5151
app_pool,
5252
None,
5353
)
54+
.await;
5455
});
5556

5657
// Give the enclave server time to bind to the socket
57-
std::thread::sleep(std::time::Duration::from_secs(1));
58+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
5859

5960
// Check that the reaper is still running, presumably waiting for
6061
// the secret.
@@ -65,14 +66,14 @@ fn reaper_works() {
6566
fs::write(&*secret_path, b"super dank tank secret tech").unwrap();
6667

6768
// Make the sure the reaper executed successfully.
68-
reaper_handle.join().unwrap();
69+
reaper_handle.await.unwrap();
6970
let contents = fs::read(integration::PIVOT_OK_SUCCESS_FILE).unwrap();
7071
assert_eq!(std::str::from_utf8(&contents).unwrap(), msg);
7172
assert!(fs::remove_file(integration::PIVOT_OK_SUCCESS_FILE).is_ok());
7273
}
7374

74-
#[test]
75-
fn reaper_handles_non_zero_exits() {
75+
#[tokio::test]
76+
async fn reaper_handles_non_zero_exits() {
7677
let secret_path: PathWrapper =
7778
"/tmp/reaper_handles_non_zero_exits.secret".into();
7879
let usock: PathWrapper = "/tmp/reaper_handles_non_zero_exits.sock".into();
@@ -100,18 +101,19 @@ fn reaper_handles_non_zero_exits() {
100101
let app_pool =
101102
StreamPool::new(SocketAddress::new_unix("./never.sock"), 1).unwrap();
102103

103-
let reaper_handle = std::thread::spawn(move || {
104+
let reaper_handle = tokio::spawn(async move {
104105
Reaper::execute(
105106
&handles,
106107
Box::new(MockNsm),
107108
enclave_pool,
108109
app_pool,
109110
None,
110111
)
112+
.await;
111113
});
112114

113115
// Give the enclave server time to bind to the socket
114-
std::thread::sleep(std::time::Duration::from_secs(1));
116+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
115117

116118
// Check that the reaper is still running, presumably waiting for
117119
// the secret.
@@ -123,15 +125,13 @@ fn reaper_handles_non_zero_exits() {
123125

124126
// Ensure the reaper has enough time to detect the secret, launch the
125127
// pivot, and let the pivot exit.
126-
std::thread::sleep(std::time::Duration::from_secs(
127-
REAPER_EXIT_DELAY_IN_SECONDS * 2,
128-
));
128+
tokio::time::sleep(REAPER_EXIT_DELAY * 2).await;
129129

130130
assert!(reaper_handle.is_finished());
131131
}
132132

133-
#[test]
134-
fn reaper_handles_panic() {
133+
#[tokio::test]
134+
async fn reaper_handles_panic() {
135135
let secret_path: PathWrapper = "/tmp/reaper_handles_panics.secret".into();
136136
let usock: PathWrapper = "/tmp/reaper_handles_panics.sock".into();
137137
let manifest_path: PathWrapper =
@@ -158,18 +158,19 @@ fn reaper_handles_panic() {
158158
let app_pool =
159159
StreamPool::new(SocketAddress::new_unix("./never.sock"), 1).unwrap();
160160

161-
let reaper_handle = std::thread::spawn(move || {
161+
let reaper_handle = tokio::spawn(async move {
162162
Reaper::execute(
163163
&handles,
164164
Box::new(MockNsm),
165165
enclave_pool,
166166
app_pool,
167167
None,
168168
)
169+
.await;
169170
});
170171

171172
// Give the enclave server time to bind to the socket
172-
std::thread::sleep(std::time::Duration::from_secs(1));
173+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
173174

174175
// Check that the reaper is still running, presumably waiting for
175176
// the secret.
@@ -181,9 +182,7 @@ fn reaper_handles_panic() {
181182

182183
// Ensure the reaper has enough time to detect the secret, launch the
183184
// pivot, and let the pivot exit.
184-
std::thread::sleep(std::time::Duration::from_secs(
185-
REAPER_EXIT_DELAY_IN_SECONDS * 2,
186-
));
185+
tokio::time::sleep(REAPER_EXIT_DELAY * 2).await;
187186

188187
assert!(reaper_handle.is_finished());
189188
}

src/qos_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ serde_bytes = { workspace = true }
2121
serde = { workspace = true }
2222

2323
futures = { workspace = true }
24-
tokio = { workspace = true, features = ["io-util", "macros", "net", "rt-multi-thread", "time", "signal"], default-features = false }
24+
tokio = { workspace = true, features = ["io-util", "macros", "net", "rt-multi-thread", "time", "signal", "process"], default-features = false }
2525
tokio-vsock = { workspace = true }
2626

2727
[dev-dependencies]

src/qos_core/src/cli.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ impl CLI {
151151
} else if opts.parsed.help() {
152152
println!("{}", opts.parsed.info());
153153
} else {
154-
// start reaper in a thread so we can terminate on ctrl+c properly
155-
std::thread::spawn(move || {
154+
// start reaper in a task so we can terminate on ctrl+c properly
155+
tokio::spawn(async move {
156156
Reaper::execute(
157157
&Handles::new(
158158
opts.ephemeral_file(),
@@ -165,7 +165,8 @@ impl CLI {
165165
.expect("Unable to create enclave socket pool"),
166166
opts.app_pool().expect("Unable to create enclave app pool"),
167167
None,
168-
);
168+
)
169+
.await;
169170
});
170171

171172
eprintln!("qos_core: Reaper running, press ctrl+c to quit");

0 commit comments

Comments
 (0)