From a67224a807bb50a72877b22fb114bb48c39acfb8 Mon Sep 17 00:00:00 2001 From: Nicolas Benes Date: Thu, 15 Oct 2026 10:54:04 +0200 Subject: [PATCH] Set RESOURCE_LOCK for tests with shared resources MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some unit tests share resources, which causes them to fail if executed in parallel. * curl_http_test uses port 19000 * prometheus exporter_test uses port 9464, bound by the prometheus-cpp Exposer that the exporter constructor starts RESOURCE_LOCK is a named mutex between tests: cases holding the same lock never run concurrently. Using two distinct lock names keeps the two groups parallel with each other and with everything else. See https://cmake.org/cmake/help/v4.5/prop_test/RESOURCE_LOCK.html Signed-off-by: Nicolas Benes Co-authored-by: Jean-François Roche Co-authored-by: Nicolas Benes --- exporters/prometheus/test/CMakeLists.txt | 4 ++++ ext/test/http/CMakeLists.txt | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/exporters/prometheus/test/CMakeLists.txt b/exporters/prometheus/test/CMakeLists.txt index 1ef890b27e..6dcf8546e2 100644 --- a/exporters/prometheus/test/CMakeLists.txt +++ b/exporters/prometheus/test/CMakeLists.txt @@ -12,3 +12,7 @@ foreach(testname exporter_test collector_test exporter_utils_test) TEST_PREFIX exporter. TEST_LIST ${testname}) endforeach() + +# prometheus exporter_test.cc: constructing an exporter starts a +# prometheus-cpp Exposer on port 9464. +set_tests_properties(${exporter_test} PROPERTIES RESOURCE_LOCK otelcpp_port_9464) diff --git a/ext/test/http/CMakeLists.txt b/ext/test/http/CMakeLists.txt index a1780586ae..671527b4b7 100644 --- a/ext/test/http/CMakeLists.txt +++ b/ext/test/http/CMakeLists.txt @@ -39,3 +39,9 @@ gtest_add_tests( TARGET ${URL_PARSER_FILENAME} TEST_PREFIX ext.http.urlparser. TEST_LIST ${URL_PARSER_FILENAME}) + +# curl_http_test.cc: every case drives a server on port 19000. +if(OTELCPP_WITH_HTTP_CLIENT_CURL) + set_tests_properties(${curl_http_test} PROPERTIES RESOURCE_LOCK + otelcpp_port_19000) +endif()