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);