From 827bff0fea950869bc07dac956b942eb21560514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Dom=C3=ADnguez=20L=C3=B3pez?= <116071334+Mario-DL@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:34:04 +0200 Subject: [PATCH] Mitigate buffer recover test flakiness on mac (#5035) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refs #21233: Run mac-ci only and buffer recover test Signed-off-by: Mario Domínguez López * Refs #21233: Test fix Signed-off-by: Mario Domínguez López * Refs #21233: Apply Elianas sugg Signed-off-by: Mario Dominguez * Refs #21233: Apply Miguels sugg Signed-off-by: Mario Dominguez * Refs #21233: TMP force multiple test runs Signed-off-by: Mario Dominguez * Revert "Refs #21233: TMP force multiple test runs" This reverts commit d3e71c9f1bcdd01b8edcbf4b5c30c3982da31e3f. * Revert "Refs #21233: Run mac-ci only and buffer recover test" This reverts commit cbc2aa125f2c51ca13b697d85dec13de2c272b57. --------- Signed-off-by: Mario Domínguez López Signed-off-by: Mario Dominguez (cherry picked from commit af92c130619405146991eedcb13b9039189d4a69) --- test/unittest/transport/SharedMemTests.cpp | 43 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/test/unittest/transport/SharedMemTests.cpp b/test/unittest/transport/SharedMemTests.cpp index cffe9d085a5..007f5e7fa21 100644 --- a/test/unittest/transport/SharedMemTests.cpp +++ b/test/unittest/transport/SharedMemTests.cpp @@ -1555,7 +1555,7 @@ TEST_F(SHMTransportTests, buffer_recover) { auto buffer = listener1->pop(); - if (buffer) + if (nullptr != buffer) { listener1_recv_count.fetch_add(1); // This is a slow listener @@ -1575,7 +1575,7 @@ TEST_F(SHMTransportTests, buffer_recover) { auto buffer = listener2->pop(); - if (buffer) + if (nullptr != buffer) { listener2_recv_count.fetch_add(1); std::this_thread::sleep_for(std::chrono::milliseconds(listener2_sleep_ms)); @@ -1676,17 +1676,48 @@ TEST_F(SHMTransportTests, buffer_recover) exit_listeners = true; + // This third part of the test just tries to cleanly + // exit the threads. + + // At this point, listeners are blocked + // in the pop() method, and the ring buffers + // may (or not) be full. + + // In order to make the listeners exit the pop() method + // we have to options: + // - Waiting for the port_timeout_ms + // - try pushing another buffer, so that cv could be + // notified. + + // Sleeping the thread waiting for the port timeout + // is more risky as the healthy timeout port watchdog + // can be triggered, so we choose the second option. + { auto buf = segment->alloc_buffer(1u, std::chrono::steady_clock::time_point()); + bool buffer_pushed = false; { is_port_ok = false; - ASSERT_TRUE(pub_sub1_write->try_push(buf, is_port_ok)); - ASSERT_TRUE(is_port_ok); + while (!buffer_pushed) + { + buffer_pushed = pub_sub1_write->try_push(buf, is_port_ok); + //! In any case port should not be ok + ASSERT_TRUE(is_port_ok); + std::this_thread::sleep_for(std::chrono::milliseconds(150)); + } } + + buffer_pushed = false; + { is_port_ok = false; - ASSERT_TRUE(pub_sub2_write->try_push(buf, is_port_ok)); - ASSERT_TRUE(is_port_ok); + while (!buffer_pushed) + { + buffer_pushed = pub_sub2_write->try_push(buf, is_port_ok); + //! In any case port should not be ok + ASSERT_TRUE(is_port_ok); + std::this_thread::sleep_for(std::chrono::milliseconds(150)); + } } }