Inline test data in the benchmark tests itself
Summary: The directory was never actually copied on apollo, so tests weren't even doing anything... Also remove fswatcher unit test, it should be rewritten correctly. Reviewers: mislav.bradac, mferencevic, buda Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1108
This commit is contained in:
parent
5418dfb19e
commit
a166c613ec
@ -2,19 +2,6 @@ file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test_results/unit)
|
||||
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test_results/benchmark)
|
||||
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/test_results/property_based)
|
||||
|
||||
# copy test data
|
||||
file(COPY ${CMAKE_SOURCE_DIR}/tests/data
|
||||
DESTINATION ${CMAKE_BINARY_DIR}/tests)
|
||||
|
||||
# move test data data to the build directory
|
||||
set(test_data "tests/data")
|
||||
set(test_data_src "${CMAKE_SOURCE_DIR}/${test_data}")
|
||||
set(test_data_dst "${CMAKE_BINARY_DIR}/${test_data}")
|
||||
add_custom_target(test_data
|
||||
COMMAND rm -rf ${test_data_dst}
|
||||
COMMAND cp -r ${test_data_src} ${test_data_dst})
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
include_directories(${GTEST_INCLUDE_DIR})
|
||||
|
||||
# benchmark test binaries
|
||||
|
@ -40,10 +40,6 @@ for test in tests:
|
||||
dirname, basename = os.path.split(path)
|
||||
files = [basename]
|
||||
|
||||
# extra files for specific tests
|
||||
if name == "unit__fswatcher":
|
||||
files.append(os.path.join("..", "data"))
|
||||
|
||||
# skip benchmark tests on diffs
|
||||
if name.startswith("benchmark") and mode == "diff":
|
||||
continue
|
||||
|
@ -10,6 +10,33 @@
|
||||
|
||||
#include "query/frontend/stripped.hpp"
|
||||
|
||||
// clang-format off
|
||||
const char *kQueries[] = {
|
||||
"MATCH (a) RETURN size(collect(a))",
|
||||
"CREATE (a:L), (b1), (b2) CREATE (a)-[:A]->(b1), (a)-[:A]->(b2)",
|
||||
"MATCH (a:L)-[rel]->(b) RETURN a, count(*)",
|
||||
"CREATE ({division: 'Sweden'})",
|
||||
"MATCH (n) RETURN n.division, count(*) ORDER BY count(*) DESC, n.division ASC",
|
||||
"UNWIND ['a', 'b', 'B', null, 'abc', 'abc1'] AS i RETURN max(i)",
|
||||
"CREATE ({created: true})",
|
||||
"MATCH (a)-[r]-(b) DELETE r, a, b RETURN count(*) AS c",
|
||||
"MATCH (u:User) WITH {key: u} AS nodes DELETE nodes.key",
|
||||
"CREATE ()-[:T {id: 42, alive: true, name: kifla, height: 4.2}]->()",
|
||||
"MATCH p = ()-[r:T]-() WHERE r.id = 42 DELETE r",
|
||||
"UNWIND range(0, 1000) AS i CREATE (:A {id: i}) MERGE (:B {id: i % 10})",
|
||||
"MATCH (n) WHERE NOT(n.name = 'apa' AND false) RETURN n",
|
||||
"CREATE ()-[:REL {property1: 12, property2: 24}]->()",
|
||||
"MATCH (n:A) WHERE n.name = 'Andres' SET n.name = 'Michael' RETURN n",
|
||||
"MATCH (n:A) SET (n).name = 'memgraph' RETURN n",
|
||||
"CREATE (a {foo: [1, 2, 3]}) SET a.foo = a.foo + [4, 5] RETURN a.foo",
|
||||
"MATCH (n:X {foo: 'A'}) SET n = {foo: 'B', baz: 'C'} RETURN n",
|
||||
"MATCH (n:X {foo: 'A'}) SET n += {foo: null} RETURN n",
|
||||
"MATCH (n) WITH n LIMIT toInteger(ceil(1.7)) RETURN count(*) AS count",
|
||||
"MATCH (a:A), (b:B) MERGE (a)-[r:TYPE]->(b) ON CREATE SET r.name = 'Lola' RETURN count(r)",
|
||||
"CREATE (:L1:L2:L3:L4:L5:L6:L7 {p1: true, p2: 42, p3: \"Here is some text that is not extremely short\", p4:\"Short text\", p5: 234.434, p6: 11.11, p7: false})",
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
auto BM_Strip = [](benchmark::State &state, auto &function, std::string query) {
|
||||
while (state.KeepRunning()) {
|
||||
for (int start = 0; start < state.range(0); start++) {
|
||||
@ -26,12 +53,8 @@ int main(int argc, char *argv[]) {
|
||||
return query::StrippedQuery(query);
|
||||
};
|
||||
|
||||
std::string path = "../../tests/data/cypher_queries/stripper/query_dict.yaml";
|
||||
std::fstream queries_file(path);
|
||||
|
||||
std::string test;
|
||||
while (std::getline(queries_file, test)) {
|
||||
benchmark::RegisterBenchmark(test.c_str(), BM_Strip, preprocess, test)
|
||||
for (auto test : kQueries) {
|
||||
benchmark::RegisterBenchmark(test, BM_Strip, preprocess, test)
|
||||
->Range(1, 1)
|
||||
->Complexity(benchmark::oN);
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
MATCH (a) RETURN size(collect(a))
|
||||
CREATE (a:L), (b1), (b2) CREATE (a)-[:A]->(b1), (a)-[:A]->(b2)
|
||||
MATCH (a:L)-[rel]->(b) RETURN a, count(*)
|
||||
CREATE ({division: 'Sweden'})
|
||||
MATCH (n) RETURN n.division, count(*) ORDER BY count(*) DESC, n.division ASC
|
||||
UNWIND ['a', 'b', 'B', null, 'abc', 'abc1'] AS i RETURN max(i)
|
||||
CREATE ({created: true})
|
||||
MATCH (a)-[r]-(b) DELETE r, a, b RETURN count(*) AS c
|
||||
MATCH (u:User) WITH {key: u} AS nodes DELETE nodes.key
|
||||
CREATE ()-[:T {id: 42, alive: true, name: kifla, height: 4.2}]->()
|
||||
MATCH p = ()-[r:T]-() WHERE r.id = 42 DELETE r
|
||||
UNWIND range(0, 1000) AS i CREATE (:A {id: i}) MERGE (:B {id: i % 10})
|
||||
MATCH (n) WHERE NOT(n.name = 'apa' AND false) RETURN n
|
||||
CREATE ()-[:REL {property1: 12, property2: 24}]->()
|
||||
MATCH (n:A) WHERE n.name = 'Andres' SET n.name = 'Michael' RETURN n
|
||||
MATCH (n:A) SET (n).name = 'memgraph' RETURN n
|
||||
CREATE (a {foo: [1, 2, 3]}) SET a.foo = a.foo + [4, 5] RETURN a.foo
|
||||
MATCH (n:X {foo: 'A'}) SET n = {foo: 'B', baz: 'C'} RETURN n
|
||||
MATCH (n:X {foo: 'A'}) SET n += {foo: null} RETURN n
|
||||
MATCH (n) WITH n LIMIT toInteger(ceil(1.7)) RETURN count(*) AS count
|
||||
MATCH (a:A), (b:B) MERGE (a)-[r:TYPE]->(b) ON CREATE SET r.name = 'Lola' RETURN count(r)
|
||||
CREATE (:L1:L2:L3:L4:L5:L6:L7 {p1: true, p2: 42, p3: "Here is some text that is not extremely short", p4:"Short text", p5: 234.434, p6: 11.11, p7: false})
|
@ -1,130 +0,0 @@
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
|
||||
#include <glog/logging.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "utils/fswatcher.hpp"
|
||||
#include "utils/signals/handler.hpp"
|
||||
#include "utils/terminate_handler.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace utils;
|
||||
|
||||
// TODO: This test is flaky, we should fix it sometime.
|
||||
|
||||
fs::path working_dir = "../data";
|
||||
fs::path filename = "test.txt";
|
||||
fs::path test_path = working_dir / filename;
|
||||
|
||||
void create_delete_loop(int iterations, ms action_delta) {
|
||||
for (int i = 0; i < iterations; ++i) {
|
||||
// create test file
|
||||
std::ofstream outfile(test_path);
|
||||
outfile.close();
|
||||
std::this_thread::sleep_for(action_delta);
|
||||
|
||||
// remove test file
|
||||
fs::remove(test_path);
|
||||
std::this_thread::sleep_for(action_delta);
|
||||
}
|
||||
}
|
||||
|
||||
void modify_loop(int iterations, ms action_delta) {
|
||||
// create test file
|
||||
std::ofstream outfile(test_path);
|
||||
outfile.close();
|
||||
std::this_thread::sleep_for(action_delta);
|
||||
|
||||
// append TEST multiple times
|
||||
for (int i = 0; i < iterations; ++i) {
|
||||
outfile.open(test_path, std::ios_base::app);
|
||||
outfile << "TEST" << i;
|
||||
outfile.close();
|
||||
std::this_thread::sleep_for(action_delta);
|
||||
}
|
||||
|
||||
// remove test file
|
||||
fs::remove(test_path);
|
||||
std::this_thread::sleep_for(action_delta);
|
||||
}
|
||||
|
||||
TEST(FSWatcherTest, CreateDeleteLoop) {
|
||||
FSWatcher watcher;
|
||||
|
||||
// parameters
|
||||
int iterations = 2;
|
||||
int created_no = 0;
|
||||
int deleted_no = 0;
|
||||
|
||||
// 3 is here because the test has to ensure that there is enough time
|
||||
// between events in order to catch all relevant events (watcher takes a
|
||||
// sleep between two undelying calls and if there is no enough time
|
||||
// some events can be overriden)
|
||||
ms action_delta = watcher.check_interval() * 3;
|
||||
|
||||
// watchers
|
||||
watcher.watch(WatchDescriptor(working_dir, FSEventType::Created),
|
||||
[&](FSEvent) {});
|
||||
watcher.watch(WatchDescriptor(working_dir, FSEventType::Deleted),
|
||||
[&](FSEvent) {});
|
||||
// above watchers should be ignored
|
||||
watcher.watch(WatchDescriptor(working_dir, FSEventType::All),
|
||||
[&](FSEvent event) {
|
||||
if (event.type == FSEventType::Created) created_no++;
|
||||
if (event.type == FSEventType::Deleted) deleted_no++;
|
||||
});
|
||||
|
||||
ASSERT_EQ(watcher.size(), 1);
|
||||
|
||||
create_delete_loop(iterations, action_delta);
|
||||
ASSERT_EQ(created_no, iterations);
|
||||
ASSERT_EQ(deleted_no, iterations);
|
||||
|
||||
watcher.unwatchAll();
|
||||
ASSERT_EQ(watcher.size(), 0);
|
||||
|
||||
watcher.unwatchAll();
|
||||
ASSERT_EQ(watcher.size(), 0);
|
||||
|
||||
create_delete_loop(iterations, action_delta);
|
||||
ASSERT_EQ(created_no, iterations);
|
||||
ASSERT_EQ(deleted_no, iterations);
|
||||
}
|
||||
|
||||
TEST(FSWatcherTest, ModifiyLoop) {
|
||||
FSWatcher watcher;
|
||||
|
||||
// parameters
|
||||
int iterations = 2;
|
||||
int modified_no = 0;
|
||||
|
||||
// 3 is here because the test has to ensure that there is enough time
|
||||
// between events in order to catch all relevant events (watcher takes a
|
||||
// sleep between two undelying calls and if there is no enough time
|
||||
// some events can be overriden)
|
||||
ms action_delta = watcher.check_interval() * 3;
|
||||
|
||||
watcher.watch(WatchDescriptor(working_dir, FSEventType::Modified),
|
||||
[&](FSEvent) { modified_no++; });
|
||||
ASSERT_EQ(watcher.size(), 1);
|
||||
|
||||
modify_loop(iterations, action_delta);
|
||||
ASSERT_EQ(modified_no, iterations);
|
||||
|
||||
watcher.unwatch(WatchDescriptor(working_dir, FSEventType::Modified));
|
||||
ASSERT_EQ(watcher.size(), 0);
|
||||
|
||||
watcher.unwatch(WatchDescriptor(working_dir, FSEventType::Modified));
|
||||
ASSERT_EQ(watcher.size(), 0);
|
||||
|
||||
modify_loop(iterations, action_delta);
|
||||
ASSERT_EQ(modified_no, iterations);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
@ -151,10 +151,6 @@ for test in tests:
|
||||
BASE_DIR_NAME + CTEST_DELIMITER + name + ".dir")
|
||||
files = [path, cmakedir]
|
||||
|
||||
# extra files for specific tests
|
||||
if name == "unit__fswatcher":
|
||||
files.append(os.path.normpath(os.path.join(dirname, "..", "data")))
|
||||
|
||||
# skip benchmark tests on diffs
|
||||
if name.startswith("benchmark") and mode == "diff":
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user