From 18fedf431fd08640c4355191cd7ecfd431ff55fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cyrille=20B=C3=A9raud?= Date: Sun, 20 Sep 2026 12:11:56 -0400 Subject: [PATCH] tests: cover pushes received by stopped runners Require immediate completion before run and after join, including a burst of notifications. Keep active-runner coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/test_dhtrunner.cpp | 52 ++++++++++++++++++++++++++++++++++++++++ tests/test_dhtrunner.h | 16 +++++++++++++ 2 files changed, 68 insertions(+) diff --git a/tests/test_dhtrunner.cpp b/tests/test_dhtrunner.cpp index 6404ec49..34bf9af8 100644 --- a/tests/test_dhtrunner.cpp +++ b/tests/test_dhtrunner.cpp @@ -16,6 +16,58 @@ using namespace std::literals; namespace test { CPPUNIT_TEST_SUITE_REGISTRATION(DhtRunnerTester); +CPPUNIT_TEST_SUITE_REGISTRATION(DhtRunnerPushTester); + +namespace { +#if defined(OPENDHT_PROXY_CLIENT) && defined(OPENDHT_PUSH_NOTIFICATIONS) +constexpr auto stoppedPushResult = dht::PushNotificationResult::IgnoredStopped; +#else +constexpr auto stoppedPushResult = dht::PushNotificationResult::IgnoredDisabled; +#endif +} + +void +DhtRunnerPushTester::testPushBeforeRun() +{ + dht::DhtRunner node; + auto result = node.pushNotificationReceived({}); + CPPUNIT_ASSERT(result.wait_for(0s) == std::future_status::ready); + CPPUNIT_ASSERT(result.get() == stoppedPushResult); +} + +void +DhtRunnerPushTester::testPushAfterJoin() +{ + dht::DhtRunner node; + node.run(0); + node.join(); + auto result = node.pushNotificationReceived({}); + CPPUNIT_ASSERT(result.wait_for(0s) == std::future_status::ready); + CPPUNIT_ASSERT(result.get() == stoppedPushResult); +} + +void +DhtRunnerPushTester::testPushBurstAfterJoin() +{ + dht::DhtRunner node; + node.run(0); + node.join(); + for (unsigned i = 0; i < 32; ++i) { + auto result = node.pushNotificationReceived({}); + CPPUNIT_ASSERT(result.wait_for(0s) == std::future_status::ready); + CPPUNIT_ASSERT(result.get() == stoppedPushResult); + } +} + +void +DhtRunnerPushTester::testPushWhileRunning() +{ + dht::DhtRunner node; + node.run(0); + auto result = node.pushNotificationReceived({}); + CPPUNIT_ASSERT(result.wait_for(5s) == std::future_status::ready); + CPPUNIT_ASSERT(result.get() != dht::PushNotificationResult::IgnoredStopped); +} template T diff --git a/tests/test_dhtrunner.h b/tests/test_dhtrunner.h index ea62d9fe..ef76364a 100644 --- a/tests/test_dhtrunner.h +++ b/tests/test_dhtrunner.h @@ -10,6 +10,22 @@ namespace test { +class DhtRunnerPushTester : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(DhtRunnerPushTester); + CPPUNIT_TEST(testPushBeforeRun); + CPPUNIT_TEST(testPushAfterJoin); + CPPUNIT_TEST(testPushBurstAfterJoin); + CPPUNIT_TEST(testPushWhileRunning); + CPPUNIT_TEST_SUITE_END(); + +public: + void testPushBeforeRun(); + void testPushAfterJoin(); + void testPushBurstAfterJoin(); + void testPushWhileRunning(); +}; + class DhtRunnerTester : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(DhtRunnerTester);