From be465f3557fa179464bc211077d7d231c5e13dc7 Mon Sep 17 00:00:00 2001 From: Volker Pacher Date: Sat, 24 Oct 2026 21:25:07 +0200 Subject: [PATCH] test/cmocka: Wait for the destroy queue between RemoveInput cases test_ws_remove_input failed in the merge queue of #2196 (run 40121904608): "Attempted to insert context with duplicate name 'ws remove input'", then obs_source_removed(input) is not true. libobs destroys sources on its destruction thread. When the second case created its input, the input of the first case was sometimes still alive, so libobs named the new one "ws remove input 2". RemoveInput then removed the old input, not the input of the case. case_teardown now waits until a pass of the destroy queue processes nothing, as obs_shutdown() does. case_setup fails with a message when libobs renamed the input. Refs #1613 Co-Authored-By: Claude Opus 5.5 --- test/cmocka/test_ws_remove_input.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/cmocka/test_ws_remove_input.cpp b/test/cmocka/test_ws_remove_input.cpp index c02ecf42b6..2ebb34c4c9 100644 --- a/test/cmocka/test_ws_remove_input.cpp +++ b/test/cmocka/test_ws_remove_input.cpp @@ -20,6 +20,7 @@ /* The C++ headers come before cmocka.h: its macros break libstdc++. */ #include +#include #include #include @@ -146,6 +147,13 @@ static int case_setup(void **) if (!scene_a || !scene_b || !input) { return -1; } + /* libobs renames an input whose name is in use. RemoveInput then finds + * a leftover from the last case instead of this input. */ + if (strcmp(obs_source_get_name(input), "ws remove input") != 0) { + fprintf(stderr, "input is named '%s': a source of the last case is still alive\n", + obs_source_get_name(input)); + return -1; + } obs_scene_add(scene_a, input); obs_scene_add(scene_b, input); return 0; @@ -166,6 +174,12 @@ static int case_teardown(void **) obs_source_remove(input); obs_source_release(input); input = nullptr; + /* libobs destroys sources on its destruction thread. Destroying a scene + * queues the destruction of its items' sources behind the wait marker, + * so wait until a pass processes nothing, as obs_shutdown() does. The + * next case can then use the same names. */ + while (obs_wait_for_destroy_queue()) + ; return 0; }