From c4857bf59584c6a0b0f830bf6e89334e1cc3d038 Mon Sep 17 00:00:00 2001 From: Adrien Beraud Date: Thu, 14 Nov 2024 15:04:37 -0500 Subject: [PATCH] tests: add testPutDuplicate --- tests/dhtrunnertester.cpp | 25 +++++++++++++++++++++++++ tests/dhtrunnertester.h | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/tests/dhtrunnertester.cpp b/tests/dhtrunnertester.cpp index 01b8a347b..8d6d23f8b 100644 --- a/tests/dhtrunnertester.cpp +++ b/tests/dhtrunnertester.cpp @@ -90,6 +90,31 @@ DhtRunnerTester::testGetPut() { CPPUNIT_ASSERT(vals.front()->data == val_data); } +void +DhtRunnerTester::testPutDuplicate() { + auto key = dht::InfoHash::get("123"); + auto val = std::make_shared("hey"); + val->id = 42; + auto val_data = val->data; + std::promise p1; + std::promise p2; + node2.put(key, val, [&](bool ok){ + p1.set_value(ok); + }); + node2.put(key, val, [&](bool ok){ + p2.set_value(ok); + }); + auto p1ret = p1.get_future().get(); + auto p2ret = p2.get_future().get(); + CPPUNIT_ASSERT(p1ret); + CPPUNIT_ASSERT(p2ret); + auto vals = node1.get(key).get(); + CPPUNIT_ASSERT(not vals.empty()); + CPPUNIT_ASSERT(vals.size() == 1); + CPPUNIT_ASSERT(vals.front()->data == val_data); +} + + void DhtRunnerTester::testListen() { std::mutex mutex; diff --git a/tests/dhtrunnertester.h b/tests/dhtrunnertester.h index 3f5afd3e4..536ffe23e 100644 --- a/tests/dhtrunnertester.h +++ b/tests/dhtrunnertester.h @@ -31,6 +31,7 @@ class DhtRunnerTester : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(DhtRunnerTester); CPPUNIT_TEST(testConstructors); CPPUNIT_TEST(testGetPut); + CPPUNIT_TEST(testPutDuplicate); CPPUNIT_TEST(testListen); CPPUNIT_TEST(testListenLotOfBytes); CPPUNIT_TEST(testIdOps); @@ -55,6 +56,10 @@ class DhtRunnerTester : public CppUnit::TestFixture { * Test get and put methods */ void testGetPut(); + /** + * Test get and multiple put + */ + void testPutDuplicate(); /** * Test listen method */