diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-18 04:55:08 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | e8ae086e6f5155764ba62596d97a0730eb424328 (patch) | |
tree | 7608793e18368aaae7c03885c684544bee01c87a | |
parent | 0b31186fe54cecd238583c060e7bd6ce9a9b1fe9 (diff) |
Add memory usage test
-rw-r--r-- | src/Log.cpp | 2 | ||||
-rw-r--r-- | tests/main.cpp | 61 |
2 files changed, 56 insertions, 7 deletions
diff --git a/src/Log.cpp b/src/Log.cpp index f033c29..9e92113 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -34,7 +34,7 @@ namespace odhtdb std::lock_guard<std::mutex> lock(mutexLog); va_list args; va_start(args, fmt); - fputs("\033[1;31Error:\033[0m ", stderr); + fputs("\033[1;31mError:\033[0m ", stderr); vfprintf(stderr, fmt, args); fputs("\n", stderr); va_end(args); 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; |