mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-07-27 09:01:50 +03:00
Moved tests under separate directory.
This commit is contained in:
@ -51,7 +51,7 @@ if (WITH_TSAN)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_custom_target(coverage_report
|
add_custom_target(coverage_report
|
||||||
lcov --capture --directory . --output lcov.info --no-external
|
lcov --capture --directory src --output lcov.info --no-external
|
||||||
COMMAND genhtml --output-directory coverage_report lcov.info)
|
COMMAND genhtml --output-directory coverage_report lcov.info)
|
||||||
|
|
||||||
|
|
||||||
@ -66,4 +66,6 @@ endif()
|
|||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
add_subdirectory(wsrep-API)
|
add_subdirectory(wsrep-API)
|
||||||
|
add_subdirectory(test)
|
||||||
|
add_subdirectory(dbsim)
|
||||||
|
|
||||||
|
8
dbsim/CMakeLists.txt
Normal file
8
dbsim/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
add_executable(dbms_simulator
|
||||||
|
dbms_simulator.cpp)
|
||||||
|
target_link_libraries(dbms_simulator wsrep-lib ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
|
||||||
|
set_property(TARGET dbms_simulator PROPERTY CXX_STANDARD 14)
|
@ -2,8 +2,6 @@
|
|||||||
# Copyright (C) 2018 Codership Oy <info@codership.com>
|
# Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add_library(wsrep-lib
|
add_library(wsrep-lib
|
||||||
client_context.cpp
|
client_context.cpp
|
||||||
id.cpp
|
id.cpp
|
||||||
@ -13,32 +11,3 @@ add_library(wsrep-lib
|
|||||||
transaction_context.cpp
|
transaction_context.cpp
|
||||||
wsrep_provider_v26.cpp)
|
wsrep_provider_v26.cpp)
|
||||||
target_link_libraries(wsrep-lib wsrep_api_v26 pthread dl)
|
target_link_libraries(wsrep-lib wsrep_api_v26 pthread dl)
|
||||||
|
|
||||||
add_executable(wsrep-lib_test
|
|
||||||
mock_client_context.cpp
|
|
||||||
test_utils.cpp
|
|
||||||
id_test.cpp
|
|
||||||
server_context_test.cpp
|
|
||||||
transaction_context_test.cpp
|
|
||||||
wsrep-lib_test.cpp
|
|
||||||
)
|
|
||||||
target_link_libraries(wsrep-lib_test wsrep-lib)
|
|
||||||
add_test(NAME wsrep-lib_test
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/wsrep-lib_test
|
|
||||||
)
|
|
||||||
|
|
||||||
if (WITH_AUTO_TEST)
|
|
||||||
set(UNIT_TEST wsrep-lib_test)
|
|
||||||
add_custom_command(
|
|
||||||
TARGET ${UNIT_TEST}
|
|
||||||
COMMENT "Run tests"
|
|
||||||
POST_BUILD
|
|
||||||
COMMAND ${UNIT_TEST}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_executable(dbms_simulator
|
|
||||||
dbms_simulator.cpp)
|
|
||||||
target_link_libraries(dbms_simulator wsrep-lib ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
|
|
||||||
set_property(TARGET dbms_simulator PROPERTY CXX_STANDARD 14)
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "wsrep/provider.hpp"
|
#include "wsrep/provider.hpp"
|
||||||
#include "wsrep/logger.hpp"
|
#include "wsrep/logger.hpp"
|
||||||
|
|
||||||
#include "mock_provider.hpp"
|
#include "../test/mock_provider.hpp"
|
||||||
#include "wsrep_provider_v26.hpp"
|
#include "wsrep_provider_v26.hpp"
|
||||||
|
|
||||||
wsrep::provider* wsrep::provider::make_provider(
|
wsrep::provider* wsrep::provider::make_provider(
|
||||||
|
27
test/CMakeLists.txt
Normal file
27
test/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
add_executable(wsrep-lib_test
|
||||||
|
mock_client_context.cpp
|
||||||
|
test_utils.cpp
|
||||||
|
id_test.cpp
|
||||||
|
server_context_test.cpp
|
||||||
|
transaction_context_test.cpp
|
||||||
|
wsrep-lib_test.cpp
|
||||||
|
)
|
||||||
|
target_link_libraries(wsrep-lib_test wsrep-lib)
|
||||||
|
add_test(NAME wsrep-lib_test
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/wsrep-lib_test
|
||||||
|
)
|
||||||
|
|
||||||
|
if (WITH_AUTO_TEST)
|
||||||
|
set(UNIT_TEST wsrep-lib_test)
|
||||||
|
add_custom_command(
|
||||||
|
TARGET ${UNIT_TEST}
|
||||||
|
COMMENT "Run tests"
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${UNIT_TEST}
|
||||||
|
)
|
||||||
|
endif()
|
85
test/server_context_test.cpp
Normal file
85
test/server_context_test.cpp
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "mock_server_context.hpp"
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct applying_server_fixture
|
||||||
|
{
|
||||||
|
applying_server_fixture()
|
||||||
|
: sc("s1", "s1",
|
||||||
|
wsrep::server_context::rm_sync)
|
||||||
|
, cc(sc,
|
||||||
|
wsrep::client_id(1),
|
||||||
|
wsrep::client_context::m_applier,
|
||||||
|
false)
|
||||||
|
, ws_handle(1, (void*)1)
|
||||||
|
, ws_meta(wsrep::gtid(wsrep::id("1"), wsrep::seqno(1)),
|
||||||
|
wsrep::stid(wsrep::id("1"), 1, 1),
|
||||||
|
wsrep::seqno(0),
|
||||||
|
wsrep::provider::flag::start_transaction |
|
||||||
|
wsrep::provider::flag::commit)
|
||||||
|
{
|
||||||
|
cc.start_transaction(ws_handle, ws_meta);
|
||||||
|
}
|
||||||
|
wsrep::mock_server_context sc;
|
||||||
|
wsrep::mock_client_context cc;
|
||||||
|
wsrep::ws_handle ws_handle;
|
||||||
|
wsrep::ws_meta ws_meta;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test on_apply() method for 1pc
|
||||||
|
BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc,
|
||||||
|
applying_server_fixture)
|
||||||
|
{
|
||||||
|
char buf[1] = { 1 };
|
||||||
|
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
|
||||||
|
wsrep::const_buffer(buf, 1)) == 0);
|
||||||
|
const wsrep::transaction_context& txc(cc.transaction());
|
||||||
|
// ::abort();
|
||||||
|
BOOST_REQUIRE_MESSAGE(
|
||||||
|
txc.state() == wsrep::transaction_context::s_committed,
|
||||||
|
"Transaction state " << txc.state() << " not committed");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test on_apply() method for 2pc
|
||||||
|
BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc,
|
||||||
|
applying_server_fixture)
|
||||||
|
{
|
||||||
|
char buf[1] = { 1 };
|
||||||
|
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
|
||||||
|
wsrep::const_buffer(buf, 1)) == 0);
|
||||||
|
const wsrep::transaction_context& txc(cc.transaction());
|
||||||
|
BOOST_REQUIRE(txc.state() == wsrep::transaction_context::s_committed);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test on_apply() method for 1pc transaction which
|
||||||
|
// fails applying and rolls back
|
||||||
|
BOOST_FIXTURE_TEST_CASE(server_context_applying_1pc_rollback,
|
||||||
|
applying_server_fixture)
|
||||||
|
{
|
||||||
|
cc.fail_next_applying_ = true;
|
||||||
|
char buf[1] = { 1 };
|
||||||
|
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
|
||||||
|
wsrep::const_buffer(buf, 1)) == 1);
|
||||||
|
const wsrep::transaction_context& txc(cc.transaction());
|
||||||
|
BOOST_REQUIRE(txc.state() == wsrep::transaction_context::s_aborted);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test on_apply() method for 2pc transaction which
|
||||||
|
// fails applying and rolls back
|
||||||
|
BOOST_FIXTURE_TEST_CASE(server_context_applying_2pc_rollback,
|
||||||
|
applying_server_fixture)
|
||||||
|
{
|
||||||
|
cc.fail_next_applying_ = true;
|
||||||
|
char buf[1] = { 1 };
|
||||||
|
BOOST_REQUIRE(sc.on_apply(cc, ws_handle, ws_meta,
|
||||||
|
wsrep::const_buffer(buf, 1)) == 1);
|
||||||
|
const wsrep::transaction_context& txc(cc.transaction());
|
||||||
|
BOOST_REQUIRE(txc.state() == wsrep::transaction_context::s_aborted);
|
||||||
|
}
|
1224
test/transaction_context_test.cpp
Normal file
1224
test/transaction_context_test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
7
test/wsrep-lib_test.cpp
Normal file
7
test/wsrep-lib_test.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
//
|
||||||
|
// Copyright (C) 2018 Codership Oy <info@codership.com>
|
||||||
|
//
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE wsrep_test
|
||||||
|
#include <boost/test/included/unit_test.hpp>
|
||||||
|
|
Reference in New Issue
Block a user