Skip to content

Commit e3310b9

Browse files
fix: ensure exit cause is propagated and sent to worker (#8)
1 parent 6eafeca commit e3310b9

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pre-compute/src/compute/app_runner.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ pub fn start_with_app<A: PreComputeAppTrait>(
4242
pre_compute_app: &mut A,
4343
chain_task_id: &str,
4444
) -> ExitMode {
45-
let exit_cause = ReplicateStatusCause::PreComputeFailedUnknownIssue;
46-
47-
match pre_compute_app.run() {
45+
let exit_cause = match pre_compute_app.run() {
4846
Ok(_) => {
4947
info!("TEE pre-compute completed");
5048
return ExitMode::Success;
5149
}
5250
Err(exit_cause) => {
5351
error!("TEE pre-compute failed with known exit cause [{exit_cause:?}]");
52+
exit_cause
5453
}
55-
}
54+
};
5655

5756
let authorization = match get_challenge(chain_task_id) {
5857
Ok(auth) => auth,
@@ -232,7 +231,7 @@ mod pre_compute_start_with_app_tests {
232231
async fn start_succeeds_when_send_exit_cause_api_success() {
233232
let mock_server = MockServer::start().await;
234233

235-
let expected_cause_enum = ReplicateStatusCause::PreComputeFailedUnknownIssue;
234+
let expected_cause_enum = ReplicateStatusCause::PreComputeOutputFolderNotFound;
236235
let expected_exit_message_payload = json!({
237236
"cause": expected_cause_enum // Relies on ReplicateStatusCause's Serialize impl
238237
});
@@ -242,14 +241,16 @@ mod pre_compute_start_with_app_tests {
242241
.and(path(format!("/compute/pre/{CHAIN_TASK_ID}/exit")))
243242
.and(body_json(expected_exit_message_payload))
244243
.respond_with(ResponseTemplate::new(200))
244+
.expect(1)
245245
.mount(&mock_server)
246246
.await;
247247

248248
let mock_server_addr_string = mock_server.address().to_string();
249249

250250
let mut mock = MockPreComputeAppTrait::new();
251251
mock.expect_run()
252-
.returning(|| Err(ReplicateStatusCause::PreComputeTeeChallengePrivateKeyMissing));
252+
.times(1)
253+
.returning(|| Err(ReplicateStatusCause::PreComputeOutputFolderNotFound));
253254

254255
// Move the blocking operations into spawn_blocking
255256
let result_code = tokio::task::spawn_blocking(move || {
@@ -266,15 +267,16 @@ mod pre_compute_start_with_app_tests {
266267
(IS_DATASET_REQUIRED, Some("false")),
267268
];
268269

269-
temp_env::with_vars(env_vars, start)
270+
temp_env::with_vars(env_vars, move || start_with_app(&mut mock, CHAIN_TASK_ID))
270271
})
271272
.await
272273
.expect("Blocking task panicked");
273274

275+
mock_server.verify().await;
274276
assert_eq!(
275277
result_code,
276278
ExitMode::ReportedFailure,
277-
"Should return 1 if sending exit cause to worker API succeeds"
279+
"Should return ExitMode::ReportedFailure if sending exit cause to worker API succeeds"
278280
);
279281
}
280282
}

0 commit comments

Comments
 (0)