diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.cpp | 61 |
1 files changed, 55 insertions, 6 deletions
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<void()> testFunc; + bool optional; +}; + int main(int argc, char **argv) { - map<string, function<void()>> testByName; - testByName["standard"] = testStandard; - testByName["two_local_nodes"] = testTwoLocalNodes; + map<string, Test> 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; |