implements PLN-0158
This commit is contained in:
@@ -121,6 +121,10 @@ impl VmSessionRegistry {
|
||||
self.get_mut(VmSessionId(task_id))
|
||||
}
|
||||
|
||||
pub fn remove_for_task(&mut self, task_id: TaskId) -> Option<VmSession> {
|
||||
self.sessions.remove(&VmSessionId(task_id))
|
||||
}
|
||||
|
||||
pub fn resident_game(&self) -> Option<&VmSession> {
|
||||
self.sessions.values().find(|session| session.app_mode == AppMode::Game)
|
||||
}
|
||||
@@ -231,6 +235,31 @@ mod tests {
|
||||
assert_eq!(registry.resident_game_for_app(43).map(|session| session.task_id), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_for_task_removes_only_matching_session() {
|
||||
let game_process = Process::new(ProcessId(1), 42, "Stress", ProcessKind::VmGame);
|
||||
let game_task = Task::new(TaskId(7), game_process.id, 42, "Stress", TaskKind::Game);
|
||||
let shell_process = Process::new(ProcessId(2), 9, "Shell", ProcessKind::VmShell);
|
||||
let shell_task = Task::new(TaskId(8), shell_process.id, 9, "Shell", TaskKind::Shell);
|
||||
let mut registry = VmSessionRegistry::new();
|
||||
|
||||
registry
|
||||
.create_for_task(&game_task, &game_process, "", None, Arc::new(AtomicU32::new(0)))
|
||||
.expect("game session should create");
|
||||
registry
|
||||
.create_for_task(&shell_task, &shell_process, "", None, Arc::new(AtomicU32::new(0)))
|
||||
.expect("shell session should create");
|
||||
|
||||
let removed = registry.remove_for_task(game_task.id).expect("game session should remove");
|
||||
|
||||
assert_eq!(removed.task_id, game_task.id);
|
||||
assert_eq!(registry.for_task(game_task.id).map(|session| session.task_id), None);
|
||||
assert_eq!(
|
||||
registry.for_task(shell_task.id).map(|session| session.task_id),
|
||||
Some(shell_task.id)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn session_runtime_state_is_independent_per_session() {
|
||||
let game_process = Process::new(ProcessId(1), 42, "Stress", ProcessKind::VmGame);
|
||||
|
||||
Reference in New Issue
Block a user