mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-03-26 17:03:09 +00:00
test(appd): add dispatch integration tests
5 async tests covering the dispatch function end-to-end: - dispatch_launch_returns_ack: LaunchApp returns LaunchAck with a positive session ID. - dispatch_terminate_known_returns_stopped: launch then terminate returns AppState::Stopped. - dispatch_terminate_unknown_returns_error: unknown session ID returns Error response. - dispatch_query_running_lists_active_sessions: after two launches, QueryRunning returns two session IDs. - dispatch_query_app_state_returns_starting: newly launched session reports AppStateKind::Starting.
This commit is contained in:
parent
6f7adc80c5
commit
b2ba6904c8
1 changed files with 104 additions and 0 deletions
|
|
@ -161,6 +161,110 @@ mod tests {
|
|||
use super::*;
|
||||
use ipc::AppStateKind;
|
||||
|
||||
fn make_registry() -> Registry {
|
||||
Arc::new(Mutex::new(SessionRegistry::default()))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dispatch_launch_returns_ack() {
|
||||
let reg = make_registry();
|
||||
let resp = dispatch(
|
||||
Request::LaunchApp {
|
||||
app_id: "com.test.app".into(),
|
||||
surface_id: 0,
|
||||
},
|
||||
®,
|
||||
)
|
||||
.await;
|
||||
match resp {
|
||||
Response::LaunchAck { session_id } => assert!(session_id > 0),
|
||||
_ => panic!("expected LaunchAck"),
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dispatch_terminate_known_returns_stopped() {
|
||||
let reg = make_registry();
|
||||
let ack = dispatch(
|
||||
Request::LaunchApp {
|
||||
app_id: "app".into(),
|
||||
surface_id: 0,
|
||||
},
|
||||
®,
|
||||
)
|
||||
.await;
|
||||
let session_id = match ack {
|
||||
Response::LaunchAck { session_id } => session_id,
|
||||
_ => panic!("expected LaunchAck"),
|
||||
};
|
||||
let resp = dispatch(Request::TerminateApp { session_id }, ®).await;
|
||||
assert!(matches!(
|
||||
resp,
|
||||
Response::AppState {
|
||||
state: AppStateKind::Stopped,
|
||||
..
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dispatch_terminate_unknown_returns_error() {
|
||||
let reg = make_registry();
|
||||
let resp = dispatch(Request::TerminateApp { session_id: 999 }, ®).await;
|
||||
assert!(matches!(resp, Response::Error { .. }));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dispatch_query_running_lists_active_sessions() {
|
||||
let reg = make_registry();
|
||||
dispatch(
|
||||
Request::LaunchApp {
|
||||
app_id: "a".into(),
|
||||
surface_id: 0,
|
||||
},
|
||||
®,
|
||||
)
|
||||
.await;
|
||||
dispatch(
|
||||
Request::LaunchApp {
|
||||
app_id: "b".into(),
|
||||
surface_id: 0,
|
||||
},
|
||||
®,
|
||||
)
|
||||
.await;
|
||||
let resp = dispatch(Request::QueryRunning, ®).await;
|
||||
match resp {
|
||||
Response::RunningApps { session_ids } => assert_eq!(session_ids.len(), 2),
|
||||
_ => panic!("expected RunningApps"),
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn dispatch_query_app_state_returns_starting() {
|
||||
let reg = make_registry();
|
||||
let ack = dispatch(
|
||||
Request::LaunchApp {
|
||||
app_id: "app".into(),
|
||||
surface_id: 0,
|
||||
},
|
||||
®,
|
||||
)
|
||||
.await;
|
||||
let session_id = match ack {
|
||||
Response::LaunchAck { session_id } => session_id,
|
||||
_ => panic!(),
|
||||
};
|
||||
let resp = dispatch(Request::QueryAppState { session_id }, ®).await;
|
||||
assert!(matches!(
|
||||
resp,
|
||||
Response::AppState {
|
||||
state: AppStateKind::Starting,
|
||||
..
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registry_launch_increments_id() {
|
||||
let mut reg = SessionRegistry::default();
|
||||
|
|
|
|||
Loading…
Reference in a new issue