Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire committed Jul 10, 2024
1 parent 21fed77 commit 3575dfa
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 42 deletions.
2 changes: 1 addition & 1 deletion include/cpprealm/networking/platform_networking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ namespace realm::networking {
default_transport_configuration m_configuration;
private:
void initialize();
std::shared_ptr<::realm::sync::SyncSocketProvider> m_provider;
std::unique_ptr<::realm::sync::SyncSocketProvider> m_provider;
};
}

Expand Down
8 changes: 4 additions & 4 deletions src/cpprealm/networking/platform_networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ namespace realm::networking {
}

private:
std::shared_ptr<websocket_observer> m_observer;
std::unique_ptr<websocket_observer> m_observer;
};

struct default_timer : public default_socket_provider::timer {
default_timer(const std::shared_ptr<::realm::sync::SyncSocketProvider::Timer>& t) : m_timer(t) {}
default_timer(std::unique_ptr<::realm::sync::SyncSocketProvider::Timer>&& t) : m_timer(std::move(t)) {}
~default_timer() = default;
void cancel() {
m_timer->cancel();
};

private:
std::shared_ptr<::realm::sync::SyncSocketProvider::Timer> m_timer;
std::unique_ptr<::realm::sync::SyncSocketProvider::Timer> m_timer;
};

/// Built in websocket client.
Expand All @@ -63,7 +63,7 @@ namespace realm::networking {

void async_write_binary(std::string_view data, websocket_interface::FunctionHandler&& handler) override;
private:
std::shared_ptr<::realm::sync::WebSocketInterface> m_ws_interface;
std::unique_ptr<::realm::sync::WebSocketInterface> m_ws_interface;
};

default_socket_provider::default_socket_provider() {
Expand Down
5 changes: 4 additions & 1 deletion tests/sync/app_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ static std::string create_jwt(const std::string& appId)
using namespace realm;

TEST_CASE("app", "[app]") {
auto app = realm::App(realm::App::configuration({Admin::Session::shared().cached_app_id(), Admin::Session::shared().base_url()}));
auto config = realm::App::configuration();
config.app_id = Admin::Session::shared().cached_app_id();
config.base_url = Admin::Session::shared().base_url();
auto app = realm::App(config);

SECTION("base_url") {
auto no_url_provided_app = realm::App(realm::App::configuration({"NA"}));
Expand Down
32 changes: 26 additions & 6 deletions tests/sync/client_reset_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ void prepare_realm(const realm::db_config& flx_sync_config, const user& sync_use
TEST_CASE("client_reset", "[sync]") {

SECTION("error handler") {
auto app = realm::App(realm::App::configuration({Admin::Session::shared().create_app({"str_col", "_id"}), Admin::Session::shared().base_url()}));
auto config = realm::App::configuration();
config.app_id = Admin::Session::shared().create_app({"str_col", "_id"});
config.base_url = Admin::Session::shared().base_url();
auto app = realm::App(config);

app.get_sync_manager().set_log_level(logger::level::all);
auto user = app.login(realm::App::credentials::anonymous()).get();
auto flx_sync_config = user.flexible_sync_configuration();
Expand All @@ -76,7 +80,11 @@ TEST_CASE("client_reset", "[sync]") {
}

SECTION("manual handler") {
auto app = realm::App(realm::App::configuration({Admin::Session::shared().create_app({"_id", "str_col"}, "test", false, false), Admin::Session::shared().base_url()}));
auto config = realm::App::configuration();
config.app_id = Admin::Session::shared().create_app({"_id", "str_col"}, "test", false, false);
config.base_url = Admin::Session::shared().base_url();
auto app = realm::App(config);

app.get_sync_manager().set_log_level(logger::level::all);
auto user = app.login(realm::App::credentials::anonymous()).get();
auto flx_sync_config = user.flexible_sync_configuration();
Expand Down Expand Up @@ -125,7 +133,10 @@ TEST_CASE("client_reset", "[sync]") {
}

SECTION("discard_unsynced_changes") {
auto app = realm::App(realm::App::configuration({Admin::Session::shared().create_app({"str_col", "_id"}, "test", false, false), Admin::Session::shared().base_url()}));
auto config = realm::App::configuration();
config.app_id = Admin::Session::shared().create_app({"_id", "str_col"}, "test", false, false);
config.base_url = Admin::Session::shared().base_url();
auto app = realm::App(config);
app.get_sync_manager().set_log_level(logger::level::all);
auto user = app.login(realm::App::credentials::anonymous()).get();

Expand Down Expand Up @@ -167,7 +178,10 @@ TEST_CASE("client_reset", "[sync]") {
}

SECTION("recover_or_discard_unsynced_changes") {
auto app = realm::App(realm::App::configuration({Admin::Session::shared().create_app({"str_col", "_id"}, "test", false, false), Admin::Session::shared().base_url()}));
auto config = realm::App::configuration();
config.app_id = Admin::Session::shared().create_app({"_id", "str_col"}, "test", false, false);
config.base_url = Admin::Session::shared().base_url();
auto app = realm::App(config);
app.get_sync_manager().set_log_level(logger::level::all);
auto user = app.login(realm::App::credentials::anonymous()).get();
auto flx_sync_config = user.flexible_sync_configuration();
Expand Down Expand Up @@ -208,7 +222,10 @@ TEST_CASE("client_reset", "[sync]") {
}

SECTION("recover_unsynced_changes") {
auto app = realm::App(realm::App::configuration({Admin::Session::shared().create_app({"str_col", "_id"}, "test", false, false), Admin::Session::shared().base_url()}));
auto config = realm::App::configuration();
config.app_id = Admin::Session::shared().create_app({"_id", "str_col"}, "test", false, false);
config.base_url = Admin::Session::shared().base_url();
auto app = realm::App(config);
app.get_sync_manager().set_log_level(logger::level::all);
auto user = app.login(realm::App::credentials::anonymous()).get();
auto flx_sync_config = user.flexible_sync_configuration();
Expand Down Expand Up @@ -249,7 +266,10 @@ TEST_CASE("client_reset", "[sync]") {
}

SECTION("recover_unsynced_changes_with_failure") {
auto app = realm::App(realm::App::configuration({Admin::Session::shared().create_app({"str_col", "_id"}, "test", false, true), Admin::Session::shared().base_url()}));
auto config = realm::App::configuration();
config.app_id = Admin::Session::shared().create_app({"_id", "str_col"}, "test", false, true);
config.base_url = Admin::Session::shared().base_url();
auto app = realm::App(config);
app.get_sync_manager().set_log_level(logger::level::all);
auto user = app.login(realm::App::credentials::anonymous()).get();
auto flx_sync_config = user.flexible_sync_configuration();
Expand Down
4 changes: 2 additions & 2 deletions tests/sync/networking_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ TEST_CASE("custom transport to proxy", "[proxy]") {
TEST_CASE("built in transport to proxy roundtrip", "[proxy]") {

tests::utils::proxy_server::config cfg;
cfg.port = 1234;
cfg.port = 1235;
cfg.server_uses_ssl = false; // Set to true if using services.cloud.mongodb.com
tests::utils::proxy_server server(std::move(cfg));

Expand All @@ -137,7 +137,7 @@ TEST_CASE("built in transport to proxy roundtrip", "[proxy]") {

auto transport_config = ::realm::networking::default_transport_configuration();
proxy_config pc;
pc.port = 1234;
pc.port = 1235;
pc.address = "127.0.0.1";
transport_config.proxy_config = pc;

Expand Down
28 changes: 0 additions & 28 deletions tests/utils/networking/proxy_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error resolving host");
}
});
} else {
Expand All @@ -91,9 +89,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error connecting to server");
}
});
} else {
Expand All @@ -106,9 +102,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error connecting to server");
}
});
}
Expand Down Expand Up @@ -163,9 +157,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error writing to server.");
}
});
}
Expand All @@ -182,9 +174,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error reading from server.");
}
});
}
Expand All @@ -207,9 +197,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error reading from client.");
}
});
}
Expand All @@ -227,9 +215,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error reading from websocket client.");
}
});

Expand Down Expand Up @@ -257,9 +243,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error writing to websocket server.");
}
});
}
Expand All @@ -279,9 +263,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error reading from websocket server.");
}
});
} else {
Expand All @@ -293,9 +275,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error reading from websocket server.");
}
});
}
Expand All @@ -313,9 +293,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error writing from websocket client.");
}
});
}
Expand All @@ -340,9 +318,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error writing to server.");
}
});
}
Expand All @@ -359,9 +335,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error reading from server.");
}
});
}
Expand Down Expand Up @@ -389,9 +363,7 @@ namespace realm::tests::utils {
} else {
if (ec == asio::error::eof) {
std::cout << "Connection closed by peer (EOF)." << std::endl;
return;
}
REALM_TERMINATE("Proxy: Error writing to client.");
}
});
}
Expand Down

0 comments on commit 3575dfa

Please sign in to comment.