From e8ae086e6f5155764ba62596d97a0730eb424328 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 18 May 2018 04:55:08 +0200 Subject: Add memory usage test --- tests/main.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/main.cpp b/tests/main.cpp index b5ce639..eaaa7ea 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -343,11 +343,56 @@ void testTwoLocalNodes() database2.seed(databaseNode); } +void testMemoryUsage() +{ + boost::filesystem::path storagePath("/tmp/odhtdbTestMemoryUsage"); + boost::filesystem::remove_all(storagePath); + boost::filesystem::create_directory(storagePath); + + auto createNodeCallback = [](const DatabaseCreateNodeRequest &request) + { + Log::debug("Create node callback"); + }; + + auto addNodeCallback = [](const DatabaseAddNodeRequest &request) + { + Log::debug("Add node callback"); + }; + + auto addUserCallback = [](const DatabaseAddUserRequest &request) + { + Log::debug("Add user callback"); + }; + + DatabaseCallbackFuncs callbackFuncs { createNodeCallback, addNodeCallback, addUserCallback }; + + Database database("bootstrap.ring.cx", 4222, storagePath, callbackFuncs); + auto databaseCreateResponse = database.create(); + DatabaseNode databaseNode = { databaseCreateResponse->getNodeEncryptionKey(), databaseCreateResponse->getRequestHash() }; + auto adminUserKey = databaseCreateResponse->getNodeAdminKeyPair(); + database.seed(databaseNode); + + const int iterations = 500; + for(int i = 0; i < iterations; ++i) + { + Log::debug("Memory usage test %d/%d", 1 + i, iterations); + database.addData(databaseNode, *adminUserKey, DataView{ (void*)"hello, world!", 13 }); + this_thread::sleep_for(chrono::milliseconds(50)); + } +} + +struct Test +{ + function testFunc; + bool optional; +}; + int main(int argc, char **argv) { - map> testByName; - testByName["standard"] = testStandard; - testByName["two_local_nodes"] = testTwoLocalNodes; + map testByName; + testByName["standard"] = { testStandard, false }; + testByName["two_local_nodes"] = { testTwoLocalNodes, false }; + testByName["memory_usage"] = { testMemoryUsage, true }; const char *testName = "all"; if(argc > 1) @@ -355,10 +400,14 @@ int main(int argc, char **argv) if(strcmp(testName, "all") == 0) { + Log::debug("Running all non-optional tests"); for(auto &testIt : testByName) { - Log::debug("Running test: %s", testIt.first.c_str()); - testIt.second(); + if(!testIt.second.optional) + { + Log::debug("Running test: %s", testIt.first.c_str()); + testIt.second.testFunc(); + } } } else @@ -371,7 +420,7 @@ int main(int argc, char **argv) } Log::debug("Running test: %s", testIt->first.c_str()); - testIt->second(); + testIt->second.testFunc(); } return 0; -- cgit v1.2.3