Skip to content

Commit 2f7dd18

Browse files
committed
test(mxc): make policy synchronization deterministic
1 parent 95c6448 commit 2f7dd18

2 files changed

Lines changed: 7 additions & 44 deletions

File tree

‎crates/openshell-server/src/grpc/policy.rs‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8656,9 +8656,7 @@ mod tests {
86568656
}
86578657

86588658
#[tokio::test]
8659-
async fn provider_free_create_waits_for_global_policy_transition() {
8660-
use openshell_core::proto::{CreateSandboxRequest, SandboxSpec};
8661-
8659+
async fn global_policy_transition_waits_for_sandbox_sync_guard() {
86628660
let state = test_server_state().await;
86638661
let guard = state.compute.sandbox_sync_guard().await;
86648662

@@ -8680,39 +8678,12 @@ mod tests {
86808678
"global update should wait for the guard"
86818679
);
86828680

8683-
let create_state = state.clone();
8684-
let create = tokio::spawn(async move {
8685-
super::super::sandbox::handle_create_sandbox(
8686-
&create_state,
8687-
authed_request(CreateSandboxRequest {
8688-
name: "provider-free-create".to_string(),
8689-
spec: Some(SandboxSpec::default()),
8690-
labels: HashMap::new(),
8691-
annotations: HashMap::new(),
8692-
workspace_scope: Some(openshell_core::proto::workspace_selector("default")),
8693-
await_main_process_attachment: false,
8694-
workload_template_name: String::new(),
8695-
}),
8696-
)
8697-
.await
8698-
});
8699-
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
8700-
assert!(
8701-
!create.is_finished(),
8702-
"provider-free create must not overlap a global policy transition"
8703-
);
8704-
87058681
drop(guard);
87068682
tokio::time::timeout(std::time::Duration::from_secs(5), update)
87078683
.await
87088684
.expect("global update should finish after guard release")
87098685
.expect("join global update")
87108686
.expect("global update should succeed");
8711-
tokio::time::timeout(std::time::Duration::from_secs(5), create)
8712-
.await
8713-
.expect("create should finish after global update")
8714-
.expect("join create")
8715-
.expect("provider-free create should succeed");
87168687
}
87178688

87188689
#[tokio::test]

‎crates/openshell-server/src/grpc/sandbox.rs‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4980,13 +4980,8 @@ mod tests {
49804980
}
49814981

49824982
#[tokio::test]
4983-
async fn create_sandbox_with_providers_waits_for_sandbox_sync_guard() {
4983+
async fn provider_free_create_waits_for_sandbox_sync_guard() {
49844984
let state = test_server_state().await;
4985-
state
4986-
.store
4987-
.put_message(&test_provider("work-github", "github"))
4988-
.await
4989-
.unwrap();
49904985

49914986
let guard = state.compute.sandbox_sync_guard().await;
49924987
let task_state = state.clone();
@@ -4995,10 +4990,7 @@ mod tests {
49954990
&task_state,
49964991
authed_request(CreateSandboxRequest {
49974992
name: "guarded-create".to_string(),
4998-
spec: Some(SandboxSpec {
4999-
providers: vec!["work-github".to_string()],
5000-
..Default::default()
5001-
}),
4993+
spec: Some(SandboxSpec::default()),
50024994
labels: HashMap::new(),
50034995
annotations: HashMap::new(),
50044996
workspace_scope: Some(openshell_core::proto::workspace_selector("default")),
@@ -5012,7 +5004,7 @@ mod tests {
50125004
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
50135005
assert!(
50145006
!task.is_finished(),
5015-
"sandbox create with initial providers should wait for sandbox sync guard"
5007+
"provider-free sandbox create should wait for sandbox sync guard"
50165008
);
50175009
drop(guard);
50185010

@@ -5022,9 +5014,9 @@ mod tests {
50225014
.expect("join create task")
50235015
.expect("create should succeed")
50245016
.into_inner();
5025-
assert_eq!(
5026-
response.sandbox.unwrap().spec.unwrap().providers,
5027-
vec!["work-github".to_string()]
5017+
assert!(
5018+
response.sandbox.unwrap().spec.unwrap().providers.is_empty(),
5019+
"the synchronization test must exercise a provider-free create"
50285020
);
50295021
}
50305022

0 commit comments

Comments
 (0)