Skip to content

Commit 0b19887

Browse files
author
Michael Wilkerson-Barker
authored
Update tests to use global logger (#6917)
* Replace local StdErrLogger with get_default_logger() * Updated changelog; fixed logger test * Fixed CI failures * Use test_context.logger for test_sync tests * Updated changelog after release
1 parent 770735e commit 0b19887

File tree

14 files changed

+54
-54
lines changed

14 files changed

+54
-54
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ CMakeScripts
2525
# Ignore build artifacts
2626
/build*
2727
/debug*
28+
/release*
2829

2930
# Ignore all user files except one which includes execution path for test
3031
*.user

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
-----------
1818

1919
### Internals
20-
* None.
20+
* Update tests to use global logger. ([PR #6917](https://github.com/realm/realm-core/pull/6917))
2121

2222
----------------------------------------------
2323

src/realm/sync/noinst/client_impl_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool ClientImpl::decompose_server_url(const std::string& url, ProtocolEnvelope&
136136

137137

138138
ClientImpl::ClientImpl(ClientConfig config)
139-
: logger_ptr{config.logger ? std::move(config.logger) : std::make_shared<util::StderrLogger>()}
139+
: logger_ptr{config.logger ? std::move(config.logger) : util::Logger::get_default_logger()}
140140
, logger{*logger_ptr}
141141
, m_reconnect_mode{config.reconnect_mode}
142142
, m_connect_timeout{config.connect_timeout}

src/realm/sync/noinst/server/server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3822,7 +3822,7 @@ void Worker::stop() noexcept
38223822

38233823

38243824
ServerImpl::ServerImpl(const std::string& root_dir, util::Optional<sync::PKey> pkey, Server::Config config)
3825-
: logger_ptr{config.logger ? std::move(config.logger) : std::make_shared<util::StderrLogger>()}
3825+
: logger_ptr{config.logger ? std::move(config.logger) : Logger::get_default_logger()}
38263826
, logger{*logger_ptr}
38273827
, m_config{std::move(config)}
38283828
, m_max_upload_backlog{determine_max_upload_backlog(config)}

test/object-store/audit.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include <realm/object-store/sync/mongo_database.hpp>
4242
#include <realm/object-store/sync/mongo_collection.hpp>
4343

44+
#include <realm/util/logger.hpp>
45+
4446
#include <catch2/catch_all.hpp>
4547

4648
#include <external/json/json.hpp>
@@ -320,8 +322,8 @@ TEST_CASE("audit object serialization", "[sync][pbs][audit]") {
320322
config.audit_config = std::make_shared<AuditConfig>();
321323
auto serializer = std::make_shared<CustomSerializer>();
322324
config.audit_config->serializer = serializer;
323-
config.audit_config->logger =
324-
std::make_shared<util::ThreadSafeLogger>(std::make_shared<util::StderrLogger>(AUDIT_LOG_LEVEL));
325+
config.audit_config->logger = std::make_shared<util::ThreadSafeLogger>(util::Logger::get_default_logger());
326+
config.audit_config->logger->set_level_threshold(AUDIT_LOG_LEVEL);
325327
auto realm = Realm::get_shared_realm(config);
326328
auto audit = realm->audit_context();
327329
REQUIRE(audit);
@@ -1507,8 +1509,9 @@ TEST_CASE("audit realm sharding", "[sync][pbs][audit]") {
15071509
{"object", {{"_id", PropertyType::Int, Property::IsPrimary{true}}, {"value", PropertyType::Int}}},
15081510
};
15091511
config.audit_config = std::make_shared<AuditConfig>();
1510-
auto logger = std::make_shared<util::StderrLogger>(AUDIT_LOG_LEVEL);
1511-
config.audit_config->logger = std::make_shared<util::ThreadSafeLogger>(logger);
1512+
auto logger = std::make_shared<util::ThreadSafeLogger>(util::Logger::get_default_logger());
1513+
logger->set_level_threshold(AUDIT_LOG_LEVEL);
1514+
config.audit_config->logger = logger;
15121515
auto realm = Realm::get_shared_realm(config);
15131516
auto audit = realm->audit_context();
15141517
REQUIRE(audit);
@@ -1611,7 +1614,7 @@ TEST_CASE("audit realm sharding", "[sync][pbs][audit]") {
16111614
// Open a different Realm with the same user and audit prefix
16121615
SyncTestFile config(test_session.app(), "other");
16131616
config.audit_config = std::make_shared<AuditConfig>();
1614-
config.audit_config->logger = std::make_shared<util::ThreadSafeLogger>(logger);
1617+
config.audit_config->logger = logger;
16151618
auto realm = Realm::get_shared_realm(config);
16161619
auto audit2 = realm->audit_context();
16171620
REQUIRE(audit2);
@@ -1638,7 +1641,7 @@ TEST_CASE("audit realm sharding", "[sync][pbs][audit]") {
16381641
// Open the same Realm with a different audit prefix
16391642
SyncTestFile config(test_session.app(), "parent");
16401643
config.audit_config = std::make_shared<AuditConfig>();
1641-
config.audit_config->logger = std::make_shared<util::ThreadSafeLogger>(logger);
1644+
config.audit_config->logger = logger;
16421645
config.audit_config->partition_value_prefix = "other";
16431646
auto realm = Realm::get_shared_realm(config);
16441647
auto audit2 = realm->audit_context();
@@ -1695,8 +1698,8 @@ TEST_CASE("audit integration tests", "[sync][pbs][audit][baas]") {
16951698
SyncTestFile config(session.app()->current_user(), bson::Bson("default"));
16961699
config.schema = schema;
16971700
config.audit_config = std::make_shared<AuditConfig>();
1698-
config.audit_config->logger =
1699-
std::make_shared<util::ThreadSafeLogger>(std::make_shared<util::StderrLogger>(AUDIT_LOG_LEVEL));
1701+
config.audit_config->logger = std::make_shared<util::ThreadSafeLogger>(util::Logger::get_default_logger());
1702+
config.audit_config->logger->set_level_threshold(AUDIT_LOG_LEVEL);
17001703

17011704
auto expect_error = [&](auto&& config, auto&& fn) -> SyncError {
17021705
std::mutex mutex;

test/object-store/c_api/c_api.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5326,11 +5326,11 @@ static void realm_app_user2(void* p, realm_user_t* user, const realm_app_error_t
53265326
TEST_CASE("C API app: link_user integration w/c_api transport", "[sync][app][c_api][baas]") {
53275327
struct TestTransportUserData {
53285328
TestTransportUserData()
5329-
: logger(std::make_unique<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL))
5329+
: logger(util::Logger::get_default_logger())
53305330
, transport(std::make_unique<SynchronousTestTransport>())
53315331
{
53325332
}
5333-
std::unique_ptr<util::Logger> logger;
5333+
std::shared_ptr<util::Logger> logger;
53345334
std::unique_ptr<realm::app::GenericNetworkTransport> transport;
53355335
};
53365336

@@ -6081,8 +6081,7 @@ TEST_CASE("C API app: websocket provider", "[sync][app][c_api][baas]") {
60816081
int free_count = 0;
60826082
};
60836083

6084-
auto logger = std::make_shared<util::StderrLogger>();
6085-
DefaultSocketProvider default_socket_provider(logger, "SocketProvider");
6084+
DefaultSocketProvider default_socket_provider(util::Logger::get_default_logger(), "SocketProvider");
60866085

60876086
auto free_fn = [](realm_userdata_t user_ptr) {
60886087
auto test_data = static_cast<TestData*>(user_ptr);

test/object-store/sync/app.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,7 @@ TEST_CASE("app: make distributable client file", "[sync][pbs][app][baas]") {
21992199
}
22002200

22012201
TEST_CASE("app: sync integration", "[sync][pbs][app][baas]") {
2202-
auto logger = std::make_shared<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
2202+
auto logger = util::Logger::get_default_logger();
22032203

22042204
const auto schema = default_app_config("").schema;
22052205

test/object-store/sync/flx_migration.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ static std::vector<ObjectId> fill_test_data(SyncTestFile& config, std::optional<
114114

115115

116116
TEST_CASE("Test server migration and rollback", "[sync][flx][flx migration][baas]") {
117-
std::shared_ptr<util::Logger> logger_ptr =
118-
std::make_shared<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
117+
auto logger_ptr = util::Logger::get_default_logger();
119118

120119
const std::string base_url = get_base_url();
121120
const std::string partition1 = "migration-test";
@@ -264,8 +263,7 @@ TEST_CASE("Test server migration and rollback", "[sync][flx][flx migration][baas
264263
}
265264

266265
TEST_CASE("Test client migration and rollback", "[sync][flx][flx migration][baas]") {
267-
std::shared_ptr<util::Logger> logger_ptr =
268-
std::make_shared<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
266+
auto logger_ptr = util::Logger::get_default_logger();
269267

270268
const std::string base_url = get_base_url();
271269
const std::string partition = "migration-test";
@@ -321,8 +319,7 @@ TEST_CASE("Test client migration and rollback", "[sync][flx][flx migration][baas
321319
}
322320

323321
TEST_CASE("Test client migration and rollback with recovery", "[sync][flx][flx migration][baas]") {
324-
std::shared_ptr<util::Logger> logger_ptr =
325-
std::make_shared<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
322+
auto logger_ptr = util::Logger::get_default_logger();
326323

327324
const std::string base_url = get_base_url();
328325
const std::string partition = "migration-test";
@@ -473,8 +470,7 @@ TEST_CASE("Test client migration and rollback with recovery", "[sync][flx][flx m
473470

474471
TEST_CASE("An interrupted migration or rollback can recover on the next session",
475472
"[sync][flx][flx migration][baas]") {
476-
std::shared_ptr<util::Logger> logger_ptr =
477-
std::make_shared<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
473+
auto logger_ptr = util::Logger::get_default_logger();
478474

479475
const std::string base_url = get_base_url();
480476
const std::string partition = "migration-test";
@@ -585,8 +581,7 @@ TEST_CASE("An interrupted migration or rollback can recover on the next session"
585581
}
586582

587583
TEST_CASE("Update to native FLX after migration", "[sync][flx][flx migration][baas]") {
588-
std::shared_ptr<util::Logger> logger_ptr =
589-
std::make_shared<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
584+
auto logger_ptr = util::Logger::get_default_logger();
590585

591586
const std::string base_url = get_base_url();
592587
const std::string partition = "migration-test";
@@ -705,8 +700,7 @@ TEST_CASE("Update to native FLX after migration", "[sync][flx][flx migration][ba
705700
}
706701

707702
TEST_CASE("New table is synced after migration", "[sync][flx][flx migration][baas]") {
708-
std::shared_ptr<util::Logger> logger_ptr =
709-
std::make_shared<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
703+
auto logger_ptr = util::Logger::get_default_logger();
710704

711705
const std::string base_url = get_base_url();
712706
const std::string partition = "migration-test";
@@ -814,8 +808,7 @@ TEST_CASE("New table is synced after migration", "[sync][flx][flx migration][baa
814808
// a subset of the one found on disk. Since it is not, a schema exception is thrown
815809
// which is eventually forwarded to the sync error handler and client reset fails.
816810
TEST_CASE("Async open + client reset", "[sync][flx][flx migration][baas]") {
817-
std::shared_ptr<util::Logger> logger_ptr =
818-
std::make_shared<util::StderrLogger>(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
811+
auto logger_ptr = util::Logger::get_default_logger();
819812

820813
const std::string base_url = get_base_url();
821814
const std::string partition = "async-open-migration-test";

test/object-store/sync/flx_sync.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,8 +2585,8 @@ TEST_CASE("flx: bootstrap batching prevents orphan documents", "[sync][flx][boot
25852585
DBOptions options;
25862586
options.encryption_key = test_util::crypt_key();
25872587
auto realm = DB::create(sync::make_client_replication(), interrupted_realm_config.path, options);
2588-
util::StderrLogger logger;
2589-
sync::PendingBootstrapStore bootstrap_store(realm, logger);
2588+
auto logger = util::Logger::get_default_logger();
2589+
sync::PendingBootstrapStore bootstrap_store(realm, *logger);
25902590
REQUIRE(bootstrap_store.has_pending());
25912591
auto pending_batch = bootstrap_store.peek_pending(1024 * 1024 * 16);
25922592
REQUIRE(pending_batch.query_version == 1);
@@ -2654,8 +2654,8 @@ TEST_CASE("flx: bootstrap batching prevents orphan documents", "[sync][flx][boot
26542654
DBOptions options;
26552655
options.encryption_key = test_util::crypt_key();
26562656
auto realm = DB::create(sync::make_client_replication(), interrupted_realm_config.path, options);
2657-
util::StderrLogger logger;
2658-
sync::PendingBootstrapStore bootstrap_store(realm, logger);
2657+
auto logger = util::Logger::get_default_logger();
2658+
sync::PendingBootstrapStore bootstrap_store(realm, *logger);
26592659
REQUIRE(bootstrap_store.has_pending());
26602660
auto pending_batch = bootstrap_store.peek_pending(1024 * 1024 * 16);
26612661
REQUIRE(pending_batch.query_version == 1);
@@ -2733,8 +2733,8 @@ TEST_CASE("flx: bootstrap batching prevents orphan documents", "[sync][flx][boot
27332733
DBOptions options;
27342734
options.encryption_key = test_util::crypt_key();
27352735
auto realm = DB::create(sync::make_client_replication(), interrupted_realm_config.path, options);
2736-
util::StderrLogger logger;
2737-
sync::PendingBootstrapStore bootstrap_store(realm, logger);
2736+
auto logger = util::Logger::get_default_logger();
2737+
sync::PendingBootstrapStore bootstrap_store(realm, *logger);
27382738
REQUIRE(bootstrap_store.has_pending());
27392739
auto pending_batch = bootstrap_store.peek_pending(1024 * 1024 * 16);
27402740
REQUIRE(pending_batch.query_version == 1);

test/object-store/util/sync/sync_test_utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,11 @@ struct FakeLocalClientReset : public TestClientReset {
382382
sync::SaltedFileIdent fake_ident{1, 123456789};
383383
auto local_db = TestHelper::get_db(local_realm);
384384
auto remote_db = TestHelper::get_db(remote_realm);
385-
util::StderrLogger logger(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
385+
auto logger = util::Logger::get_default_logger();
386+
386387
using _impl::client_reset::perform_client_reset_diff;
387388
constexpr bool recovery_is_allowed = true;
388-
perform_client_reset_diff(local_db, remote_db, fake_ident, logger, m_mode, recovery_is_allowed, nullptr,
389+
perform_client_reset_diff(local_db, remote_db, fake_ident, *logger, m_mode, recovery_is_allowed, nullptr,
389390
nullptr, nullptr);
390391

391392
remote_realm->close();

0 commit comments

Comments
 (0)