aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-18 04:55:08 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commite8ae086e6f5155764ba62596d97a0730eb424328 (patch)
tree7608793e18368aaae7c03885c684544bee01c87a /tests
parent0b31186fe54cecd238583c060e7bd6ce9a9b1fe9 (diff)
Add memory usage test
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp61
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;