From 8fc7c3ba75c58ff2e635439d66cf7a233be3ee38 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Wed, 11 May 2022 14:48:54 +0300 Subject: [PATCH 1/9] Log level added --- lib/src/app.dart | 38 ++++++++++++++++++++++++++++++++++ lib/src/native/realm_core.dart | 1 + 2 files changed, 39 insertions(+) diff --git a/lib/src/app.dart b/lib/src/app.dart index ccdbf68f5..d9878d92f 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -36,6 +36,41 @@ enum MetadataPersistenceMode { disabled, } +/// Specifies the criticality level above which messages will be logged +/// by the default sync client logger. +enum LogLevel { + /// Log everything. This will seriously harm the performance of the + /// sync client and should never be used in production scenarios. + all, + + /// A version of 'debug' that allows for very high volume output. + /// This may seriously affect the performance of the sync client. + trace, + + /// Reveal information that can aid debugging, no longer paying + /// attention to efficiency. + debug, + + /// Same as 'Info', but prioritize completeness over minimalism. + detail, + + /// Log operational sync client messages, but in a minimalistic fashion to + /// avoid general overhead from logging and to keep volume down. + info, + + /// Log errors and warnings. + warn, + + /// Log errors only. + error, + + /// Log only fatal errors. + fatal, + + /// Log nothing. + off, +} + @immutable /// A class exposing configuration options for an [App] @@ -76,6 +111,9 @@ class AppConfiguration { /// Enumeration that specifies how and if logged-in User objects are persisted across application launches. final MetadataPersistenceMode metadataPersistenceMode; + /// Gets or sets the [LogLevel] for sync operations. + final LogLevel logLevel; + /// The encryption key to use for user metadata on this device, if [metadataPersistenceMode] is /// [MetadataPersistenceMode.encrypted]. /// diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index 3f4cb901c..118583dc5 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -836,6 +836,7 @@ class _RealmCore { _realmLib.realm_sync_client_config_set_base_file_path(handle._pointer, configuration.baseFilePath.path.toUtf8Ptr(arena)); _realmLib.realm_sync_client_config_set_metadata_mode(handle._pointer, configuration.metadataPersistenceMode.index); + _realmLib.realm_sync_client_config_set_log_level(handle._pointer, configuration.logLevel.index); if (configuration.metadataEncryptionKey != null && configuration.metadataPersistenceMode == MetadataPersistenceMode.encrypted) { _realmLib.realm_sync_client_config_set_metadata_encryption_key(handle._pointer, configuration.metadataEncryptionKey!.toUint8Ptr(arena)); From 09851c8be5f7d8a8cd76aca8c562316082958bd8 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Wed, 11 May 2022 16:16:46 +0300 Subject: [PATCH 2/9] Fix logLevel variable --- lib/src/app.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/src/app.dart b/lib/src/app.dart index d9878d92f..577bef16d 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -72,7 +72,6 @@ enum LogLevel { } @immutable - /// A class exposing configuration options for an [App] /// {@category Application} class AppConfiguration { @@ -112,7 +111,7 @@ class AppConfiguration { final MetadataPersistenceMode metadataPersistenceMode; /// Gets or sets the [LogLevel] for sync operations. - final LogLevel logLevel; + late LogLevel logLevel; /// The encryption key to use for user metadata on this device, if [metadataPersistenceMode] is /// [MetadataPersistenceMode.encrypted]. From 537dc00fe79afacffeacce1a60851b782ad42dd8 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Wed, 11 May 2022 17:13:05 +0300 Subject: [PATCH 3/9] Realm core methods call implementation --- lib/src/app.dart | 44 ++++++++++++++++++++++++++++++---- lib/src/native/realm_core.dart | 5 ++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/lib/src/app.dart b/lib/src/app.dart index 577bef16d..0627dfb25 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -38,6 +38,7 @@ enum MetadataPersistenceMode { /// Specifies the criticality level above which messages will be logged /// by the default sync client logger. +/// {@category Application} enum LogLevel { /// Log everything. This will seriously harm the performance of the /// sync client and should never be used in production scenarios. @@ -71,7 +72,30 @@ enum LogLevel { off, } +/// Enum describing what should happen in case of a Client Resync. +/// +/// A Client Resync is triggered if the device and server cannot agree +/// on a common shared history for the Realm file, +/// thus making it impossible for the device to upload or receive any changes. +/// This can happen if the server is rolled back or restored from backup. +/// {@category Application} +enum ClientResyncMode { + /// A manual Client Resync is also known as a Client Reset. + /// + /// A ``ClientResetRequiredError` will be sent to `SyncSession.ErrorHandler.onError(SyncSession, ObjectServerError)`, + /// triggering a Client Reset. Doing this provides a handle to both the old and new Realm file, + /// enabling full control of which changes to move, if any. + /// This is the only supported mode for Query-based Realms. + Manual, + + /// The local Realm will be discarded and replaced with the server side Realm. + /// All local changes will be lost. + /// This mode is not yet supported by Query-based Realms. + DiscardLocal, +} + @immutable + /// A class exposing configuration options for an [App] /// {@category Application} class AppConfiguration { @@ -110,9 +134,6 @@ class AppConfiguration { /// Enumeration that specifies how and if logged-in User objects are persisted across application launches. final MetadataPersistenceMode metadataPersistenceMode; - /// Gets or sets the [LogLevel] for sync operations. - late LogLevel logLevel; - /// The encryption key to use for user metadata on this device, if [metadataPersistenceMode] is /// [MetadataPersistenceMode.encrypted]. /// @@ -120,6 +141,16 @@ class AppConfiguration { /// Setting this will not change the encryption key for individual Realms, which is set in the [Configuration]. final List? metadataEncryptionKey; + /// The [LogLevel] for sync operations. + final LogLevel logLevel; + + /// The default HTTP request timeout in milliseconds. + final int requestTimeout; + + /// Value of [ClientResyncMode] describing what should happen in case of a Client Resync. + /// Default value is [ClientResyncMode.Manual]. + final ClientResyncMode clientResyncMode; + /// The [HttpClient] that will be used for HTTP requests during authentication. /// /// You can use this to override the default http client handler and configure settings like proxies, @@ -138,6 +169,9 @@ class AppConfiguration { this.localAppVersion, this.metadataEncryptionKey, this.metadataPersistenceMode = MetadataPersistenceMode.plaintext, + this.logLevel = LogLevel.error, + this.requestTimeout = 0, + this.clientResyncMode = ClientResyncMode.Manual, HttpClient? httpClient, }) : baseUrl = baseUrl ?? Uri.parse('https://realm.mongodb.com'), baseFilePath = baseFilePath ?? Directory(Configuration.filesPath), @@ -178,7 +212,7 @@ class App { } /// Removes the user's local credentials. This will also close any associated Sessions. - /// + /// /// If [user] is null logs out [currentUser] if it exists. Future logout([User? user]) async { return await realmCore.logOut(this, user); @@ -188,7 +222,7 @@ class App { Future removeUser(User user) async { return await realmCore.removeUser(this, user); } - + /// Switches the [currentUser] to the one specified in [user]. void switchUser(User user) { realmCore.switchUser(this, user); diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index 118583dc5..cb7936be9 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -837,6 +837,11 @@ class _RealmCore { _realmLib.realm_sync_client_config_set_base_file_path(handle._pointer, configuration.baseFilePath.path.toUtf8Ptr(arena)); _realmLib.realm_sync_client_config_set_metadata_mode(handle._pointer, configuration.metadataPersistenceMode.index); _realmLib.realm_sync_client_config_set_log_level(handle._pointer, configuration.logLevel.index); + if (configuration.requestTimeout > 0) { + _realmLib.realm_sync_client_config_set_connect_timeout(handle._pointer, configuration.requestTimeout); + } + + //_realmLib.realm_sync_config_set_resync_mode(handle._pointer, configuration.clientResyncMode.index); if (configuration.metadataEncryptionKey != null && configuration.metadataPersistenceMode == MetadataPersistenceMode.encrypted) { _realmLib.realm_sync_client_config_set_metadata_encryption_key(handle._pointer, configuration.metadataEncryptionKey!.toUint8Ptr(arena)); From 574c79dd524f7cd24de8e8d56f89c1cb9690c1cf Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Thu, 12 May 2022 15:20:23 +0300 Subject: [PATCH 4/9] Tests --- CHANGELOG.md | 3 ++- lib/src/app.dart | 27 -------------------------- lib/src/native/realm_core.dart | 3 --- lib/src/realm_class.dart | 2 +- test/app_test.dart | 35 ++++++++++++++++++++++++++++++++++ 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3f01ffa6..0b262d896 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * Support ObjectId type. ([#468](https://github.com/realm/realm-dart/pull/468)) * Support Uuid type. ([#470](https://github.com/realm/realm-dart/pull/470)) * Support application login. ([#469](https://github.com/realm/realm-dart/pull/469)) +* Support app configuration log level and request timeout. * Support EmailPassword register user. ([#452](https://github.com/realm/realm-dart/pull/452)) * Support EmailPassword confirm user. ([#478](https://github.com/realm/realm-dart/pull/478)) * Support EmailPassword resend user confirmation email. ([#479](https://github.com/realm/realm-dart/pull/479)) @@ -33,7 +34,7 @@ * Support user state. ([#525](https://github.com/realm/realm-dart/pull/525)) * Support getting user id and identities. ([#525](https://github.com/realm/realm-dart/pull/525)) * Support user logout. ([#525](https://github.com/realm/realm-dart/pull/525)) - +. ### Fixed * Fixed an issue that would result in the wrong transaction being rolled back if you start a write transaction inside a write transaction. ([#442](https://github.com/realm/realm-dart/issues/442)) * Fixed boolean value persistence ([#474](https://github.com/realm/realm-dart/issues/474)) diff --git a/lib/src/app.dart b/lib/src/app.dart index 0627dfb25..83a0f3d3c 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -72,28 +72,6 @@ enum LogLevel { off, } -/// Enum describing what should happen in case of a Client Resync. -/// -/// A Client Resync is triggered if the device and server cannot agree -/// on a common shared history for the Realm file, -/// thus making it impossible for the device to upload or receive any changes. -/// This can happen if the server is rolled back or restored from backup. -/// {@category Application} -enum ClientResyncMode { - /// A manual Client Resync is also known as a Client Reset. - /// - /// A ``ClientResetRequiredError` will be sent to `SyncSession.ErrorHandler.onError(SyncSession, ObjectServerError)`, - /// triggering a Client Reset. Doing this provides a handle to both the old and new Realm file, - /// enabling full control of which changes to move, if any. - /// This is the only supported mode for Query-based Realms. - Manual, - - /// The local Realm will be discarded and replaced with the server side Realm. - /// All local changes will be lost. - /// This mode is not yet supported by Query-based Realms. - DiscardLocal, -} - @immutable /// A class exposing configuration options for an [App] @@ -147,10 +125,6 @@ class AppConfiguration { /// The default HTTP request timeout in milliseconds. final int requestTimeout; - /// Value of [ClientResyncMode] describing what should happen in case of a Client Resync. - /// Default value is [ClientResyncMode.Manual]. - final ClientResyncMode clientResyncMode; - /// The [HttpClient] that will be used for HTTP requests during authentication. /// /// You can use this to override the default http client handler and configure settings like proxies, @@ -171,7 +145,6 @@ class AppConfiguration { this.metadataPersistenceMode = MetadataPersistenceMode.plaintext, this.logLevel = LogLevel.error, this.requestTimeout = 0, - this.clientResyncMode = ClientResyncMode.Manual, HttpClient? httpClient, }) : baseUrl = baseUrl ?? Uri.parse('https://realm.mongodb.com'), baseFilePath = baseFilePath ?? Directory(Configuration.filesPath), diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index cb7936be9..117626d6b 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -840,9 +840,6 @@ class _RealmCore { if (configuration.requestTimeout > 0) { _realmLib.realm_sync_client_config_set_connect_timeout(handle._pointer, configuration.requestTimeout); } - - //_realmLib.realm_sync_config_set_resync_mode(handle._pointer, configuration.clientResyncMode.index); - if (configuration.metadataEncryptionKey != null && configuration.metadataPersistenceMode == MetadataPersistenceMode.encrypted) { _realmLib.realm_sync_client_config_set_metadata_encryption_key(handle._pointer, configuration.metadataEncryptionKey!.toUint8Ptr(arena)); } diff --git a/lib/src/realm_class.dart b/lib/src/realm_class.dart index 69a94aa38..341d9e2ce 100644 --- a/lib/src/realm_class.dart +++ b/lib/src/realm_class.dart @@ -30,7 +30,7 @@ import 'realm_object.dart'; import 'results.dart'; // always expose with `show` to explicitly control the public API surface -export 'app.dart' show AppConfiguration, MetadataPersistenceMode, App; +export 'app.dart' show AppConfiguration, MetadataPersistenceMode, LogLevel, App; export 'package:realm_common/realm_common.dart' show Ignored, diff --git a/test/app_test.dart b/test/app_test.dart index 4e80da85b..91bdda730 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -16,6 +16,7 @@ // //////////////////////////////////////////////////////////////////////////////// +import 'dart:convert'; import 'dart:io'; import 'package:test/expect.dart'; @@ -34,6 +35,8 @@ Future main([List? args]) async { expect(a.baseFilePath.path, Configuration.filesPath); expect(a.baseUrl, Uri.parse('https://realm.mongodb.com')); expect(a.defaultRequestTimeout, const Duration(minutes: 1)); + expect(a.logLevel, LogLevel.error); + expect(a.metadataPersistenceMode, MetadataPersistenceMode.plaintext); final httpClient = HttpClient(context: SecurityContext(withTrustedRoots: false)); final b = AppConfiguration( @@ -43,15 +46,47 @@ Future main([List? args]) async { defaultRequestTimeout: const Duration(seconds: 2), localAppName: 'bar', localAppVersion: "1.0.0", + metadataPersistenceMode: MetadataPersistenceMode.disabled, + logLevel: LogLevel.info, + requestTimeout: 1000, httpClient: httpClient, ); expect(b.appId, 'myapp1'); expect(b.baseFilePath.path, Directory.systemTemp.path); expect(b.baseUrl, Uri.parse('https://not_re.al')); expect(b.defaultRequestTimeout, const Duration(seconds: 2)); + expect(b.logLevel, LogLevel.info); + expect(b.metadataPersistenceMode, MetadataPersistenceMode.disabled); + expect(b.requestTimeout, 1000); expect(b.httpClient, httpClient); }); + test('AppConfiguration can be created and an App could be created', () { + final httpClient = HttpClient(context: SecurityContext(withTrustedRoots: false)); + final appConfig = AppConfiguration( + 'myapp1', + baseFilePath: Directory.systemTemp, + baseUrl: Uri.parse('https://not_re.al'), + defaultRequestTimeout: const Duration(seconds: 2), + localAppName: 'bar', + localAppVersion: "1.0.0", + metadataPersistenceMode: MetadataPersistenceMode.encrypted, + metadataEncryptionKey: base64.decode("ekey"), + logLevel: LogLevel.info, + requestTimeout: 1000, + httpClient: httpClient, + ); + final app = App(appConfig); + expect(app.configuration.appId, 'myapp1'); + expect(app.configuration.baseFilePath.path, Directory.systemTemp.path); + expect(app.configuration.baseUrl, Uri.parse('https://not_re.al')); + expect(app.configuration.defaultRequestTimeout, const Duration(seconds: 2)); + expect(app.configuration.logLevel, LogLevel.info); + expect(app.configuration.metadataPersistenceMode, MetadataPersistenceMode.encrypted); + expect(app.configuration.requestTimeout, 1000); + expect(app.configuration.httpClient, httpClient); + }); + test('App can be created', () async { final configuration = AppConfiguration(generateRandomString(10)); final app = App(configuration); From 42602d503e483486263ecc3c62a0d761f2e278bc Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Thu, 12 May 2022 15:21:24 +0300 Subject: [PATCH 5/9] CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b262d896..174d62a8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ * Support ObjectId type. ([#468](https://github.com/realm/realm-dart/pull/468)) * Support Uuid type. ([#470](https://github.com/realm/realm-dart/pull/470)) * Support application login. ([#469](https://github.com/realm/realm-dart/pull/469)) -* Support app configuration log level and request timeout. +* Support app configuration log level and request timeout.([#566](https://github.com/realm/realm-dart/pull/566)) * Support EmailPassword register user. ([#452](https://github.com/realm/realm-dart/pull/452)) * Support EmailPassword confirm user. ([#478](https://github.com/realm/realm-dart/pull/478)) * Support EmailPassword resend user confirmation email. ([#479](https://github.com/realm/realm-dart/pull/479)) From 93ea7f2d39f4b4ab21bbd7a75a33e5f8f7b7fea6 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova <95419820+desistefanova@users.noreply.github.com> Date: Mon, 16 May 2022 12:11:59 +0300 Subject: [PATCH 6/9] Update CHANGELOG.md Co-authored-by: blagoev --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba8e00f67..515fe523f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,6 @@ * Support user state. ([#525](https://github.com/realm/realm-dart/pull/525)) * Support getting user id and identities. ([#525](https://github.com/realm/realm-dart/pull/525)) * Support user logout. ([#525](https://github.com/realm/realm-dart/pull/525)) -. ### Fixed * Fixed an issue that would result in the wrong transaction being rolled back if you start a write transaction inside a write transaction. ([#442](https://github.com/realm/realm-dart/issues/442)) * Fixed boolean value persistence ([#474](https://github.com/realm/realm-dart/issues/474)) From 4f860c48b08e0fa1390782a85d22e5f9f04cbde5 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Mon, 16 May 2022 13:16:22 +0300 Subject: [PATCH 7/9] Code review changes --- lib/src/app.dart | 15 ++++++++++----- lib/src/native/realm_core.dart | 4 +--- test/app_test.dart | 24 ++++++++++++++++++------ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/src/app.dart b/lib/src/app.dart index 8a184633b..a2ddebbc6 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -77,6 +77,8 @@ enum LogLevel { /// A class exposing configuration options for an [App] /// {@category Application} class AppConfiguration { + static const int defaultConnectionTimeout = 120000; + /// The [appId] is the unique id that identifies the Realm application. final String appId; @@ -95,6 +97,12 @@ class AppConfiguration { /// The [defaultRequestTimeout] for HTTP requests. Defaults to 60 seconds. final Duration defaultRequestTimeout; + /// The maximum duration to allow for a connection to + /// become fully established. This includes the time to resolve the + /// network address, the TCP connect operation, the SSL handshake, and + /// the WebSocket handshake. Defaults to 2 minutes. + final Duration maxConnectionTimeout; + /// The [localAppName] is the friendly name identifying the current client application. /// /// This is typically used to differentiate between client applications that use the same @@ -122,9 +130,6 @@ class AppConfiguration { /// The [LogLevel] for sync operations. final LogLevel logLevel; - /// The default HTTP request timeout in milliseconds. - final int requestTimeout; - /// The [HttpClient] that will be used for HTTP requests during authentication. /// /// You can use this to override the default http client handler and configure settings like proxies, @@ -132,7 +137,7 @@ class AppConfiguration { /// normal circumstances, they can be useful if client devices are behind corporate firewall or use /// a more complex networking setup. final HttpClient httpClient; - + /// Instantiates a new [AppConfiguration] with the specified appId. AppConfiguration( this.appId, { @@ -144,7 +149,7 @@ class AppConfiguration { this.metadataEncryptionKey, this.metadataPersistenceMode = MetadataPersistenceMode.plaintext, this.logLevel = LogLevel.error, - this.requestTimeout = 0, + this.maxConnectionTimeout = const Duration(minutes: 2), HttpClient? httpClient, }) : baseUrl = baseUrl ?? Uri.parse('https://realm.mongodb.com'), baseFilePath = baseFilePath ?? Directory(Configuration.filesPath), diff --git a/lib/src/native/realm_core.dart b/lib/src/native/realm_core.dart index 117626d6b..7dac65f6e 100644 --- a/lib/src/native/realm_core.dart +++ b/lib/src/native/realm_core.dart @@ -837,9 +837,7 @@ class _RealmCore { _realmLib.realm_sync_client_config_set_base_file_path(handle._pointer, configuration.baseFilePath.path.toUtf8Ptr(arena)); _realmLib.realm_sync_client_config_set_metadata_mode(handle._pointer, configuration.metadataPersistenceMode.index); _realmLib.realm_sync_client_config_set_log_level(handle._pointer, configuration.logLevel.index); - if (configuration.requestTimeout > 0) { - _realmLib.realm_sync_client_config_set_connect_timeout(handle._pointer, configuration.requestTimeout); - } + _realmLib.realm_sync_client_config_set_connect_timeout(handle._pointer, configuration.maxConnectionTimeout.inMicroseconds); if (configuration.metadataEncryptionKey != null && configuration.metadataPersistenceMode == MetadataPersistenceMode.encrypted) { _realmLib.realm_sync_client_config_set_metadata_encryption_key(handle._pointer, configuration.metadataEncryptionKey!.toUint8Ptr(arena)); } diff --git a/test/app_test.dart b/test/app_test.dart index db7431a76..ad31cc803 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -29,7 +29,7 @@ Future main([List? args]) async { await setupTests(args); - test('AppConfiguration can be created', () { + test('AppConfiguration can be initialized', () { final a = AppConfiguration('myapp'); expect(a.appId, 'myapp'); expect(a.baseFilePath.path, Configuration.filesPath); @@ -48,7 +48,7 @@ Future main([List? args]) async { localAppVersion: "1.0.0", metadataPersistenceMode: MetadataPersistenceMode.disabled, logLevel: LogLevel.info, - requestTimeout: 1000, + maxConnectionTimeout: const Duration(minutes: 1), httpClient: httpClient, ); expect(b.appId, 'myapp1'); @@ -57,11 +57,23 @@ Future main([List? args]) async { expect(b.defaultRequestTimeout, const Duration(seconds: 2)); expect(b.logLevel, LogLevel.info); expect(b.metadataPersistenceMode, MetadataPersistenceMode.disabled); - expect(b.requestTimeout, 1000); + expect(b.maxConnectionTimeout, const Duration(minutes: 1)); expect(b.httpClient, httpClient); }); + +test('AppConfiguration can be created with defaults', () { + final appConfig = AppConfiguration('myapp1'); + final app = App(appConfig); + expect(app.configuration.appId, 'myapp1'); + expect(app.configuration.baseUrl, Uri.parse('https://realm.mongodb.com')); + expect(app.configuration.defaultRequestTimeout, const Duration(minutes: 1)); + expect(app.configuration.logLevel, LogLevel.error); + expect(app.configuration.metadataPersistenceMode, MetadataPersistenceMode.plaintext); + expect(app.configuration.maxConnectionTimeout, const Duration(minutes: 2)); + expect(app.configuration.httpClient, isNotNull); + }); - test('AppConfiguration can be created and an App could be created', () { + test('AppConfiguration can be created', () { final httpClient = HttpClient(context: SecurityContext(withTrustedRoots: false)); final appConfig = AppConfiguration( 'myapp1', @@ -73,7 +85,7 @@ Future main([List? args]) async { metadataPersistenceMode: MetadataPersistenceMode.encrypted, metadataEncryptionKey: base64.decode("ekey"), logLevel: LogLevel.info, - requestTimeout: 1000, + maxConnectionTimeout: const Duration(minutes: 1), httpClient: httpClient, ); final app = App(appConfig); @@ -83,7 +95,7 @@ Future main([List? args]) async { expect(app.configuration.defaultRequestTimeout, const Duration(seconds: 2)); expect(app.configuration.logLevel, LogLevel.info); expect(app.configuration.metadataPersistenceMode, MetadataPersistenceMode.encrypted); - expect(app.configuration.requestTimeout, 1000); + expect(app.configuration.maxConnectionTimeout, const Duration(minutes: 1)); expect(app.configuration.httpClient, httpClient); }); From 8fdb0641318b9019a5a4fcba0aedbdf24ed4dc6e Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Mon, 16 May 2022 13:19:15 +0300 Subject: [PATCH 8/9] Removed constant --- lib/src/app.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/app.dart b/lib/src/app.dart index a2ddebbc6..0e3b49802 100644 --- a/lib/src/app.dart +++ b/lib/src/app.dart @@ -77,7 +77,6 @@ enum LogLevel { /// A class exposing configuration options for an [App] /// {@category Application} class AppConfiguration { - static const int defaultConnectionTimeout = 120000; /// The [appId] is the unique id that identifies the Realm application. final String appId; From a522ae7301375b9db0a2aad25b09f495a6ed0725 Mon Sep 17 00:00:00 2001 From: Desislava Stefanova Date: Tue, 17 May 2022 11:54:42 +0300 Subject: [PATCH 9/9] Code review changes --- test/app_test.dart | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/app_test.dart b/test/app_test.dart index ad31cc803..dae88b954 100644 --- a/test/app_test.dart +++ b/test/app_test.dart @@ -30,16 +30,16 @@ Future main([List? args]) async { await setupTests(args); test('AppConfiguration can be initialized', () { - final a = AppConfiguration('myapp'); - expect(a.appId, 'myapp'); - expect(a.baseFilePath.path, Configuration.filesPath); - expect(a.baseUrl, Uri.parse('https://realm.mongodb.com')); - expect(a.defaultRequestTimeout, const Duration(minutes: 1)); - expect(a.logLevel, LogLevel.error); - expect(a.metadataPersistenceMode, MetadataPersistenceMode.plaintext); + final defaultAppConfig = AppConfiguration('myapp'); + expect(defaultAppConfig.appId, 'myapp'); + expect(defaultAppConfig.baseFilePath.path, Configuration.filesPath); + expect(defaultAppConfig.baseUrl, Uri.parse('https://realm.mongodb.com')); + expect(defaultAppConfig.defaultRequestTimeout, const Duration(minutes: 1)); + expect(defaultAppConfig.logLevel, LogLevel.error); + expect(defaultAppConfig.metadataPersistenceMode, MetadataPersistenceMode.plaintext); final httpClient = HttpClient(context: SecurityContext(withTrustedRoots: false)); - final b = AppConfiguration( + final appConfig = AppConfiguration( 'myapp1', baseFilePath: Directory.systemTemp, baseUrl: Uri.parse('https://not_re.al'), @@ -51,14 +51,14 @@ Future main([List? args]) async { maxConnectionTimeout: const Duration(minutes: 1), httpClient: httpClient, ); - expect(b.appId, 'myapp1'); - expect(b.baseFilePath.path, Directory.systemTemp.path); - expect(b.baseUrl, Uri.parse('https://not_re.al')); - expect(b.defaultRequestTimeout, const Duration(seconds: 2)); - expect(b.logLevel, LogLevel.info); - expect(b.metadataPersistenceMode, MetadataPersistenceMode.disabled); - expect(b.maxConnectionTimeout, const Duration(minutes: 1)); - expect(b.httpClient, httpClient); + expect(appConfig.appId, 'myapp1'); + expect(appConfig.baseFilePath.path, Directory.systemTemp.path); + expect(appConfig.baseUrl, Uri.parse('https://not_re.al')); + expect(appConfig.defaultRequestTimeout, const Duration(seconds: 2)); + expect(appConfig.logLevel, LogLevel.info); + expect(appConfig.metadataPersistenceMode, MetadataPersistenceMode.disabled); + expect(appConfig.maxConnectionTimeout, const Duration(minutes: 1)); + expect(appConfig.httpClient, httpClient); }); test('AppConfiguration can be created with defaults', () {