Skip to content

Commit

Permalink
refactor: Simplify namespaces in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shmocz committed Sep 23, 2023
1 parent 6b68a42 commit da0a6cf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 43 deletions.
10 changes: 4 additions & 6 deletions tests/test_dll_inject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

using instrumentation_client::InstrumentationClient;
using namespace std::chrono_literals;
namespace connection = ra2yrcpp::connection;
using namespace ra2yrcpp::test_util;
using namespace ra2yrcpp;

class DLLInjectTest : public ::testing::Test {
protected:
Expand Down Expand Up @@ -103,7 +103,7 @@ TEST_F(DLLInjectTest, IServiceDLLInjectTest) {
dll_inject::DLLInjectOptions());

std::unique_ptr<InstrumentationClient> client;
ra2yrcpp::asio_utils::IOService srv;
asio_utils::IOService srv;

util::call_until(5.0s, 1.0s, [&]() {
try {
Expand All @@ -126,10 +126,8 @@ TEST_F(DLLInjectTest, IServiceDLLInjectTest) {
std::string key = "key1";

// TODO(shmocz): don't ignore return value
(void)ra2yrcpp::client_utils::run(StoreValue::create({key, f1}),
client.get());
auto r2 =
ra2yrcpp::client_utils::run(GetValue::create({key, ""}), client.get());
(void)client_utils::run(StoreValue::create({key, f1}), client.get());
auto r2 = client_utils::run(GetValue::create({key, ""}), client.get());
ASSERT_EQ(r2.value(), f1);
}

Expand Down
28 changes: 12 additions & 16 deletions tests/test_instrumentation_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,30 @@ using namespace ra2yrcpp::test_util;

namespace lib = websocketpp::lib;
namespace pb = google::protobuf;
namespace client_utils = ra2yrcpp::client_utils;

using instrumentation_client::InstrumentationClient;
using ra2yrcpp::InstrumentationService;

class InstrumentationServiceTest : public ::testing::Test {
using conn_t = ra2yrcpp::connection::ClientWebsocketConnection;
using conn_t = connection::ClientWebsocketConnection;

protected:
void SetUp() override;
void TearDown() override;

virtual void init() = 0;
std::unique_ptr<ra2yrcpp::asio_utils::IOService> srv;
std::unique_ptr<asio_utils::IOService> srv;
std::shared_ptr<conn_t> conn;
std::unique_ptr<InstrumentationService> I;
std::unique_ptr<InstrumentationClient> client;
std::unique_ptr<client_utils::CommandSender> cs;
};

void InstrumentationServiceTest::SetUp() {
InstrumentationService::Options O = ra2yrcpp::default_options;
InstrumentationService::Options O = default_options;

srv = std::make_unique<ra2yrcpp::asio_utils::IOService>();
srv = std::make_unique<asio_utils::IOService>();
I = std::unique_ptr<InstrumentationService>(InstrumentationService::create(
O, ra2yrcpp::commands_builtin::get_commands(), nullptr));
O, commands_builtin::get_commands(), nullptr));

conn = std::make_shared<conn_t>(O.server.host, std::to_string(O.server.port),
srv.get());
Expand Down Expand Up @@ -189,11 +187,11 @@ TEST_F(IServiceTest, TestHTTPRequest) {
#if 0
B("ra2yrproto.commands.GetSystemState");
Use these commands to re - generate the string message.auto* mm =
ra2yrcpp::create_command_message(&B, "");
create_command_message(&B, "");
auto cc =
ra2yrcpp::create_command(*mm, ra2yrproto::CommandType::CLIENT_COMMAND);
create_command(*mm, ra2yrproto::CommandType::CLIENT_COMMAND);
cc.set_blocking(true);
auto cmd_json = ra2yrcpp::protocol::to_json(cc);
auto cmd_json = protocol::to_json(cc);
#endif
// FIXME(shmocz): adding this delay fixes the unpack error. Race condition?
std::string cmd_json2 =
Expand All @@ -209,11 +207,11 @@ TEST_F(IServiceTest, TestHTTPRequest) {
"{}\r\n\r\n{}",
cmd_json2.size(), cmd_json2);

auto S0 = std::make_shared<ra2yrcpp::asio_utils::IOService>();
auto S0 = std::make_shared<asio_utils::IOService>();

const int count = 32;
for (int i = 0; i < count; i++) {
ra2yrcpp::asio_utils::AsioSocket A(S0);
asio_utils::AsioSocket A(S0);

A.connect(I->opts().server.host, std::to_string(I->opts().server.port));
auto sz = A.write(msg);
Expand All @@ -231,15 +229,13 @@ TEST_F(IServiceTest, TestHTTPRequest) {

ASSERT_TRUE(std::regex_search(rsp, match, re));
ASSERT_GT(match.size(), 1);
auto bbody = ra2yrcpp::to_bytes(rsp.substr(rsp.find("\r\n\r\n") + 4));
auto bbody = to_bytes(rsp.substr(rsp.find("\r\n\r\n") + 4));
ra2yrproto::Response R;
ASSERT_TRUE(ra2yrcpp::protocol::from_json(bbody, &R));
ASSERT_TRUE(protocol::from_json(bbody, &R));
}
iprintf("exit test");
}

namespace command = ra2yrcpp::command;

class CommandTest : public ::testing::Test {
protected:
void SetUp() {
Expand Down
12 changes: 4 additions & 8 deletions tests/test_is_stress_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
#include <string>
#include <vector>

using namespace multi_client;

using ra2yrcpp::InstrumentationService;
using ra2yrcpp::tests::MultiClientTestContext;
using namespace ra2yrcpp;
using namespace ra2yrcpp::test_util;

class ISStressTest : public ::testing::Test {
protected:
void SetUp() override {
I = std::unique_ptr<InstrumentationService>(InstrumentationService::create(
ra2yrcpp::default_options, ra2yrcpp::commands_builtin::get_commands(),
nullptr));
ctx = std::make_unique<MultiClientTestContext>();
default_options, commands_builtin::get_commands(), nullptr));
ctx = std::make_unique<tests::MultiClientTestContext>();
}

void TearDown() override {
Expand All @@ -36,7 +32,7 @@ class ISStressTest : public ::testing::Test {
}

std::unique_ptr<InstrumentationService> I;
std::unique_ptr<MultiClientTestContext> ctx;
std::unique_ptr<tests::MultiClientTestContext> ctx;
};

TEST_F(ISStressTest, DISABLED_ManyConnections) {
Expand Down
9 changes: 4 additions & 5 deletions tests/test_multi_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@
#include <vector>

using namespace std::chrono_literals;
using namespace multi_client;
using namespace ra2yrcpp::test_util;
using namespace ra2yrcpp;

using ra2yrcpp::InstrumentationService;
using ra2yrcpp::tests::MultiClientTestContext;
namespace client_utils = ra2yrcpp::client_utils;

class MultiClientTest : public ::testing::Test {
protected:
void SetUp() override {
InstrumentationService::Options opts = ra2yrcpp::default_options;
InstrumentationService::Options opts = default_options;

I = std::unique_ptr<InstrumentationService>(InstrumentationService::create(
opts, ra2yrcpp::commands_builtin::get_commands(), nullptr));
opts, commands_builtin::get_commands(), nullptr));
ctx = std::make_unique<MultiClientTestContext>();
ctx->create_client(multi_client::default_options);
cs = std::make_unique<client_utils::CommandSender>([&](auto& msg) {
auto r = ctx->clients[0]->send_command(msg);
return ra2yrcpp::protocol::from_any<ra2yrproto::CommandResult>(r.body());
return protocol::from_any<ra2yrproto::CommandResult>(r.body());
});
}

Expand Down
16 changes: 8 additions & 8 deletions tests/test_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace fs = std::filesystem;
namespace pb = google::protobuf;
using namespace ra2yrcpp;

class TemporaryDirectoryTest : public ::testing::Test {
protected:
Expand Down Expand Up @@ -54,7 +55,7 @@ TEST_F(TemporaryDirectoryTest, ProtocolTest) {
record_path.string(), std::ios_base::out | std::ios_base::binary);

const bool use_gzip = true;
ra2yrcpp::protocol::MessageOstream MS(record_out, use_gzip);
protocol::MessageOstream MS(record_out, use_gzip);

if (std::any_of(messages.begin(), messages.end(),
[&MS](const auto& G) { return !MS.write(G); })) {
Expand All @@ -63,13 +64,12 @@ TEST_F(TemporaryDirectoryTest, ProtocolTest) {
}

ASSERT_TRUE(fs::is_regular_file(record_path));
ra2yrcpp::protocol::dump_messages(record_path.string(),
ra2yrproto::ra2yr::GameState(),
[&messages_out](auto* M) {
ra2yrproto::ra2yr::GameState G;
G.CopyFrom(*M);
messages_out.push_back(G);
});
protocol::dump_messages(record_path.string(), ra2yrproto::ra2yr::GameState(),
[&messages_out](auto* M) {
ra2yrproto::ra2yr::GameState G;
G.CopyFrom(*M);
messages_out.push_back(G);
});

pb::util::MessageDifferencer D;
for (std::size_t i = 0; i < messages.size(); i++) {
Expand Down

0 comments on commit da0a6cf

Please sign in to comment.