Skip to content

Commit

Permalink
Added back realm_app_config_set_sync_client_config() CAPI function
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wilkerson-Barker committed Jul 16, 2024
1 parent ad8ba53 commit 193f2f3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3023,7 +3023,10 @@ RLM_API void realm_app_config_set_metadata_mode(realm_app_config_t*,
RLM_API void realm_app_config_set_metadata_encryption_key(realm_app_config_t*, const uint8_t[64]) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_security_access_group(realm_app_config_t*, const char*) RLM_API_NOEXCEPT;

RLM_API realm_sync_client_config_t* realm_app_config_get_sync_client_config(realm_app_config_t*) RLM_API_NOEXCEPT;
// This function does not take ownership of the realm_sync_client_config_t pointer,
// so this will need to be released manually after calling this function.
RLM_API void realm_app_config_set_sync_client_config(realm_app_config_t* app_config,
realm_sync_client_config_t* sc_config) RLM_API_NOEXCEPT;

/**
* Get an existing @a realm_app_credentials_t and return it's json representation
Expand Down
6 changes: 6 additions & 0 deletions src/realm/object-store/c_api/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ RLM_API const char* realm_app_credentials_serialize_as_json(realm_app_credential
});
}

RLM_API void realm_app_config_set_sync_client_config(realm_app_config_t* app_config,
realm_sync_client_config_t* sc_config) noexcept
{
app_config->sync_client_config = *sc_config;
}

RLM_API realm_app_t* realm_app_create(const realm_app_config_t* app_config)
{
return wrap_err([&] {
Expand Down
41 changes: 29 additions & 12 deletions test/object-store/c_api/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,28 +545,39 @@ TEST_CASE("C API (non-database)", "[c_api]") {
realm_sync_client_config_set_multiplex_sessions(test_sync_client_config.get(), true);
CHECK(test_sync_client_config->multiplex_sessions);
realm_sync_client_config_set_multiplex_sessions(test_sync_client_config.get(), false);
CHECK_FALSE(test_sync_client_config->multiplex_sessions);
realm_sync_client_config_set_user_agent_binding_info(test_sync_client_config.get(), "some user agent stg");
CHECK(test_sync_client_config->user_agent_binding_info == "some user agent stg");
realm_sync_client_config_set_user_agent_application_info(test_sync_client_config.get(), "some application");
CHECK(test_sync_client_config->user_agent_application_info == "some application");
realm_sync_client_config_set_connect_timeout(test_sync_client_config.get(), 666);
CHECK(test_sync_client_config->timeouts.connect_timeout == 666);
realm_sync_client_config_set_connection_linger_time(test_sync_client_config.get(), 999);
CHECK(test_sync_client_config->timeouts.connection_linger_time == 999);
realm_sync_client_config_set_ping_keepalive_period(test_sync_client_config.get(), 555);
CHECK(test_sync_client_config->timeouts.ping_keepalive_period == 555);
realm_sync_client_config_set_pong_keepalive_timeout(test_sync_client_config.get(), 100000);
CHECK(test_sync_client_config->timeouts.pong_keepalive_timeout == 100000);
realm_sync_client_config_set_fast_reconnect_limit(test_sync_client_config.get(), 1099);
CHECK(test_sync_client_config->timeouts.fast_reconnect_limit == 1099);
realm_sync_client_config_set_resumption_delay_interval(test_sync_client_config.get(), 1024);
CHECK(test_sync_client_config->timeouts.reconnect_backoff_info.resumption_delay_interval.count() == 1024);
realm_sync_client_config_set_max_resumption_delay_interval(test_sync_client_config.get(), 600024);
CHECK(test_sync_client_config->timeouts.reconnect_backoff_info.max_resumption_delay_interval.count() ==
600024);
realm_sync_client_config_set_resumption_delay_backoff_multiplier(test_sync_client_config.get(), 1010);
CHECK(test_sync_client_config->timeouts.reconnect_backoff_info.resumption_delay_backoff_multiplier == 1010);
auto verify_sync_client_config = [](SyncClientConfig* config) {
CHECK_FALSE(config->multiplex_sessions);
CHECK(config->user_agent_binding_info == "some user agent stg");
CHECK(config->user_agent_application_info == "some application");
CHECK(config->timeouts.connect_timeout == 666);
CHECK(config->timeouts.connection_linger_time == 999);
CHECK(config->timeouts.ping_keepalive_period == 555);
CHECK(config->timeouts.pong_keepalive_timeout == 100000);
CHECK(config->timeouts.fast_reconnect_limit == 1099);
CHECK(config->timeouts.reconnect_backoff_info.resumption_delay_interval.count() == 1024);
CHECK(config->timeouts.reconnect_backoff_info.max_resumption_delay_interval.count() == 600024);
CHECK(config->timeouts.reconnect_backoff_info.resumption_delay_backoff_multiplier == 1010);
};
verify_sync_client_config(test_sync_client_config.get());

// Make a dummy app config and make sure the values are updated after set
const uint64_t request_timeout = 2500;
auto transport = std::make_shared<UnitTestTransport>(request_timeout);
auto http_transport = realm_http_transport(transport);
auto app_config = cptr(realm_app_config_new("app_id_123", &http_transport));
realm_app_config_set_sync_client_config(app_config.get(), test_sync_client_config.get());
// Make sure app_config's sync_client_config has the values set above
verify_sync_client_config(&app_config->sync_client_config);
}

#if !REALM_APP_SERVICES
Expand Down Expand Up @@ -824,6 +835,12 @@ TEST_CASE("C API (non-database)", "[c_api]") {
realm_app_config_set_metadata_mode(app_config.get(), RLM_SYNC_CLIENT_METADATA_MODE_DISABLED);
realm_app_config_set_security_access_group(app_config.get(), "");

auto sync_client_config = cptr(realm_sync_client_config_new());
realm_sync_client_config_set_connect_timeout(sync_client_config.get(), 9876543); // some bogus value
realm_app_config_set_sync_client_config(app_config.get(), sync_client_config.get());
// Make sure app_config's sync_client_config has the value we set
CHECK(app_config->sync_client_config.timeouts.connect_timeout == 9876543);

auto test_app = cptr(realm_app_create(app_config.get()));
realm_user_t* sync_user;
auto user_data_free = [](realm_userdata_t) {};
Expand Down

0 comments on commit 193f2f3

Please sign in to comment.