Skip to content

Commit

Permalink
CA-394882: avoid error on tasks that are not ours
Browse files Browse the repository at this point in the history
The previous unit test step has created some tasks, and deleted them when completed.
However it didn't look at events.
The next step was waiting for some newly created tasks to complete and looking at events.
But it was processing all events, even those that it wasn't watching for.
These events may have referred to tasks that were already deleted.

Fix the code to only query the state of the tasks that we are waiting for
(if these go missing, it is a bug).

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
  • Loading branch information
edwintorok committed Jun 26, 2024
1 parent c787cb4 commit d78ebc0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ocaml/xenopsd/test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ let wait_for_tasks id =
List.iter
(function
| Dynamic.Task id' ->
if task_ended dbg id' then ids := StringSet.remove id' !ids
(* ignore events on tasks that are not ours, they may have been deleted *)
if StringSet.mem id' !ids && task_ended dbg id' then
ids := StringSet.remove id' !ids
| _ ->
()
)
Expand All @@ -100,6 +102,7 @@ let wait_for_tasks id =

let success_task id =
let t = Client.TASK.stat dbg id in
D.debug "%s: destroying task %s" __FUNCTION__ id ;
Client.TASK.destroy dbg id ;
match t.Task.state with
| Task.Completed _ ->
Expand All @@ -119,6 +122,7 @@ let success_task id =

let fail_not_built_task id =
let t = Client.TASK.stat dbg id in
D.debug "%s: destroying task %s" __FUNCTION__ id ;
Client.TASK.destroy dbg id ;
match t.Task.state with
| Task.Completed _ ->
Expand All @@ -140,6 +144,7 @@ let fail_not_built_task id =

let fail_invalid_vcpus_task id =
let t = Client.TASK.stat dbg id in
D.debug "%s: destroying task %s" __FUNCTION__ id ;
Client.TASK.destroy dbg id ;
match t.Task.state with
| Task.Completed _ ->
Expand Down Expand Up @@ -515,6 +520,7 @@ let vm_test_parallel_start_shutdown _ =
) ;
let t = Unix.gettimeofday () in
let tasks = List.map (fun id -> Client.VM.start dbg id false) ids in
D.debug "Waiting for tasks: %s" (String.concat ", " tasks) ;
wait_for_tasks tasks ;
if !verbose_timings then (
Printf.fprintf stderr "Cleaning up tasks\n" ;
Expand Down

0 comments on commit d78ebc0

Please sign in to comment.