Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire committed Jul 8, 2024
1 parent 2fba092 commit d4ef3a8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
8 changes: 5 additions & 3 deletions include/cpprealm/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,13 @@ class App {
std::optional<std::string> base_url;
/// Custom location for Realm files.
std::optional<std::string> path;
// Extra HTTP headers to be set on each request to Atlas Device Sync when using the internal HTTP client.
/// Extra HTTP headers to be set on each request to Atlas Device Sync when using the internal HTTP client.
std::optional<std::map<std::string, std::string>> custom_http_headers;
// Custom encryption key for the metadata Realm.
/// Custom encryption key for the metadata Realm.
std::optional<std::array<char, 64>> metadata_encryption_key;
// Network proxy configuration to be set on each HTTP and WebSocket request.
/// Caches an App and its configuration for a given App ID. On by default.
bool enable_caching = true;
/// Network proxy configuration to be set on each HTTP and WebSocket request.
std::optional<sync_config::proxy_config> proxy_configuration;
/**
* Optionally provide a custom HTTP transport for network calls to the server.
Expand Down
2 changes: 2 additions & 0 deletions include/cpprealm/networking/platform_networking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <cpprealm/version_numbers.hpp>
#endif

#include <chrono>

namespace realm {
namespace app {
struct GenericNetworkTransport;
Expand Down
3 changes: 2 additions & 1 deletion src/cpprealm/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ namespace realm {
app_config.device_info = std::move(device_info);

app_config.sync_client_config = client_config;
m_app = app::App::get_app(app::App::CacheMode::Enabled, std::move(app_config));
m_app = app::App::get_app(config.enable_caching ? app::App::CacheMode::Enabled : app::App::CacheMode::Disabled,
std::move(app_config));
}

App::App(const std::string &app_id,
Expand Down
2 changes: 0 additions & 2 deletions src/cpprealm/networking/platform_networking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <realm/sync/network/default_socket.hpp>
#include <realm/util/platform_info.hpp>

#include <chrono>

namespace realm::networking {

std::shared_ptr<http_transport_client> make_default_http_client() {
Expand Down
19 changes: 5 additions & 14 deletions tests/sync/networking_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "../utils/networking/proxy_server.hpp"

#include <iostream>

using namespace realm;

TEST_CASE("sends plaintext data to proxy", "[proxy]") {
Expand All @@ -27,9 +25,8 @@ TEST_CASE("sends plaintext data to proxy", "[proxy]") {
config.proxy_configuration = pc;
config.app_id = Admin::Session::shared().cached_app_id();
config.base_url = Admin::Session::shared().base_url();

std::cout << "should call foo_socket_provider" << "\n";

config.enable_caching = false;

struct foo_socket_provider : public ::realm::networking::default_socket_provider {
std::unique_ptr<::realm::networking::websocket_interface> connect(std::unique_ptr<::realm::networking::websocket_observer> o,
::realm::networking::websocket_endpoint&& ep) override {
Expand All @@ -39,7 +36,6 @@ TEST_CASE("sends plaintext data to proxy", "[proxy]") {
ep.url.replace(0, from.length(), to);
}
m_called = true;
std::cout << "foo_socket_provider: called" << "\n";
return ::realm::networking::default_socket_provider::connect(std::move(o), std::move(ep));
}

Expand All @@ -53,7 +49,6 @@ TEST_CASE("sends plaintext data to proxy", "[proxy]") {

auto foo_socket = std::make_shared<foo_socket_provider>();
config.sync_socket_provider = foo_socket;
std::cout << "should call foo_http_transport" << "\n";

struct foo_http_transport : public ::realm::networking::default_http_transport {
void send_request_to_server(const ::realm::networking::request& request,
Expand All @@ -65,7 +60,6 @@ TEST_CASE("sends plaintext data to proxy", "[proxy]") {
req_copy.url.replace(0, from.length(), to);
}
m_called = true;
std::cout << "foo_http_transport: called" << "\n";
return ::realm::networking::default_http_transport::send_request_to_server(req_copy, std::move(completion));
}

Expand Down Expand Up @@ -115,11 +109,8 @@ TEST_CASE("sends plaintext data to proxy", "[proxy]") {

bool is_subset = std::includes(expected_events.begin(), expected_events.end(), proxy_events.begin(), proxy_events.end());
CHECK(is_subset);
std::cout << "foo_http_transport: called" << foo_transport->was_called() <<"\n";
std::cout << "foo_socket: called" << foo_socket->was_called() <<"\n";

// CHECK(foo_transport->was_called());
// CHECK(foo_socket->was_called());
CHECK(foo_transport->was_called());
CHECK(foo_socket->was_called());
}

TEST_CASE("proxy roundtrip", "[proxy]") {
Expand Down Expand Up @@ -177,4 +168,4 @@ TEST_CASE("proxy roundtrip", "[proxy]") {

bool is_subset = std::includes(expected_events.begin(), expected_events.end(), proxy_events.begin(), proxy_events.end());
CHECK(is_subset);
}
}

0 comments on commit d4ef3a8

Please sign in to comment.