-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d89662f
commit aea4586
Showing
12 changed files
with
1,712 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
cmake_minimum_required( VERSION 3.10 ) | ||
project(dsr_tests | ||
VERSION 2024.11.12 | ||
DESCRIPTION "DSR Tests" | ||
LANGUAGES CXX) | ||
|
||
|
||
Include(FetchContent) | ||
|
||
FetchContent_Declare( | ||
Catch2 | ||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git | ||
GIT_TAG v3.7.1 | ||
) | ||
|
||
FetchContent_MakeAvailable(Catch2) | ||
|
||
#include(~/software/vcpkg/scripts/buildsystems/vcpkg.cmake) | ||
|
||
|
||
find_package(Boost REQUIRED) | ||
find_package(Qt6 COMPONENTS Core REQUIRED) | ||
find_package(Eigen3 3.3 REQUIRED NO_MODULE) | ||
|
||
|
||
|
||
add_executable(tests test.cpp | ||
graph/edge_operations.cpp | ||
graph/node_operations.cpp | ||
graph/graph_operations.cpp | ||
graph/attribute_operations.cpp | ||
graph/convenience_operations.cpp | ||
crdt/crdt_operations.cpp | ||
synchronization/graph_synchronization.cpp | ||
synchronization/type_translation.cpp | ||
synchronization/graph_signals.cpp | ||
utils.h) | ||
|
||
|
||
set_target_properties(tests PROPERTIES | ||
CMAKE_CXX_STANDARD 23 | ||
CXX_STANDARD_REQUIRED ON | ||
CXX_EXTENSIONS ON) | ||
|
||
target_compile_options(tests PUBLIC -g -std=c++23) | ||
|
||
|
||
target_link_libraries(tests PRIVATE | ||
Catch2::Catch2WithMain | ||
Robocomp::dsr_api | ||
Robocomp::dsr_core | ||
Boost::boost | ||
Qt6::Core | ||
Eigen3::Eigen | ||
fastdds | ||
fastcdr) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// | ||
// Created by jc on 5/11/24. | ||
// | ||
|
||
#include "../utils.h" | ||
#include "catch2/catch_test_macros.hpp" | ||
|
||
#include <cstdint> | ||
#include <dsr/core/crdt/delta_crdt.h> | ||
|
||
|
||
struct dt{ | ||
|
||
std::string m_str; | ||
|
||
dt(const std::string &str) : m_str(str) {} | ||
dt(std::string &&str) : m_str(str) {} | ||
dt(const char *str) : m_str(str) {} | ||
|
||
auto agent_id() -> uint32_t { return m_str.size();} | ||
auto operator<=>(const dt&) const = default; | ||
|
||
}; | ||
|
||
TEST_CASE("CRDT operations and state", "[CRDT][CONSISTENCY]") { | ||
|
||
mvreg<dt> o1, o2, o3; | ||
mvreg<dt> delta, delta2, delta3, delta4; | ||
|
||
delta = o1.write("hello"); | ||
delta2 = delta3 = delta; | ||
|
||
o2.join(std::move(delta)); | ||
o3.join(std::move(delta2)); | ||
//o1 and o2 and o3 are in the same state. | ||
REQUIRE(o1.read_reg().m_str == "hello"); | ||
REQUIRE(o2.read_reg().m_str == "hello"); | ||
REQUIRE(o3.read_reg().m_str == "hello"); | ||
|
||
|
||
//check out of order joins. | ||
delta = o2.write("world"); | ||
REQUIRE(o2.read_reg().m_str == "world"); | ||
delta = o2.write("hello world"); | ||
delta3 = delta; | ||
REQUIRE(o2.read_reg().m_str == "hello world"); | ||
|
||
delta2 = o3.write("I'm o3"); | ||
REQUIRE(o3.read_reg().m_str == "I'm o3"); | ||
|
||
o1.join(std::move(delta)); | ||
REQUIRE(o1.read_reg().m_str == "hello world"); | ||
o1.join(std::move(delta2)); | ||
//o2 is newer than o3 operation (the implementation uses a counter). | ||
REQUIRE(o1.read_reg().m_str == "hello world"); | ||
o3.join(std::move(delta3)); | ||
REQUIRE(o3.read_reg().m_str == "hello world"); | ||
|
||
//check that in can solve conflicts (same counter) automatically using the smaller agent_id() method of the datatype. | ||
delta = o2.write("~~~~~~~~~~~~"); | ||
delta2 = o3.write("I win"); | ||
delta3 = delta2; | ||
delta4 = delta; | ||
o1.join(std::move(delta)); | ||
REQUIRE(o1.read_reg().m_str == "~~~~~~~~~~~~"); | ||
o1.join(std::move(delta2)); | ||
o2.join(std::move(delta3)); | ||
o3.join(std::move(delta4)); | ||
REQUIRE(o1.read_reg().m_str == "I win"); | ||
REQUIRE(o2.read_reg().m_str == "I win"); | ||
REQUIRE(o3.read_reg().m_str == "I win"); | ||
|
||
} |
Oops, something went wrong.