Skip to content
Permalink
Browse files

dhtproxy: test put/get mtu with 40k chars

  • Loading branch information...
binarytrails authored and aberaud committed Sep 29, 2019
1 parent 128af52 commit ac10afac44ef66a944a0ed01412393cd749dce0d
Showing with 50 additions and 1 deletion.
  1. +45 −0 tests/dhtproxytester.cpp
  2. +5 −1 tests/dhtproxytester.h
@@ -207,4 +207,49 @@ DhtProxyTester::testResubscribeGetValues() {
CPPUNIT_ASSERT(firstVal_data == values.front());
}

void
DhtProxyTester::testPutGet40KChars()
{
// Arrange
auto key = dht::InfoHash::get("testPutGet40KChars");
std::vector<std::shared_ptr<dht::Value>> values;
std::string mtu = "";
for (int i = 0; i < 40000; i++){
if (i % 2 == 0)
mtu.append("M");
else
mtu.append("T");
}
std::condition_variable cv;
std::mutex cv_m;
std::unique_lock<std::mutex> lk(cv_m);
bool done_put = false;
bool done_get = false;

// Act
dht::Value val {mtu};
nodeClient->put(key, std::move(val), [&](bool ok) {
std::lock_guard<std::mutex> lk(cv_m);
done_put = ok;
cv.notify_all();
});
CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(10), [&]{ return done_put; }));

nodeClient->get(key, [&](const std::vector<std::shared_ptr<dht::Value>>& vals){
values = vals;
return true;
},[&](bool ok){
std::lock_guard<std::mutex> lk(cv_m);
done_get = ok;
cv.notify_all();
});
CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(10), [&]{ return done_get; }));

// Assert
dht::Value mtu_val {mtu};
for (const auto &value: values){
CPPUNIT_ASSERT(value->data == mtu_val.data);
}
}

} // namespace test
@@ -34,6 +34,7 @@ class DhtProxyTester : public CppUnit::TestFixture {
CPPUNIT_TEST(testGetPut);
CPPUNIT_TEST(testListen);
CPPUNIT_TEST(testResubscribeGetValues);
CPPUNIT_TEST(testPutGet40KChars);
CPPUNIT_TEST_SUITE_END();

public:
@@ -54,12 +55,15 @@ class DhtProxyTester : public CppUnit::TestFixture {
* Test listen
*/
void testListen();

/**
* When a proxy redo a subscribe on the proxy
* it should retrieve existant values
*/
void testResubscribeGetValues();
/**
* Test MTU put/get on dht
*/
void testPutGet40KChars();

private:
dht::DhtRunner nodePeer;

0 comments on commit ac10afa

Please sign in to comment.
You can’t perform that action at this time.