From 893f12e39f3d27959827b9c8e87e7a8a81396e63 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Sat, 12 Aug 2023 18:34:01 +0530 Subject: [PATCH] Updated defaultLogger to create a singleTon, updated realtimeClient with testSink --- .../Helpers/DefaultLogger.cs | 21 ++++++++++++++++++- .../Realtime/DeltaSandboxSpecs.cs | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/IO.Ably.Tests.Shared/Helpers/DefaultLogger.cs b/src/IO.Ably.Tests.Shared/Helpers/DefaultLogger.cs index 5edf2c6c0..dd68deda8 100644 --- a/src/IO.Ably.Tests.Shared/Helpers/DefaultLogger.cs +++ b/src/IO.Ably.Tests.Shared/Helpers/DefaultLogger.cs @@ -5,7 +5,26 @@ namespace IO.Ably.Tests.Shared.Helpers /// An utility class for logging various messages. public static class DefaultLogger { - internal static ILogger LoggerInstance => InternalLogger.Create(); + private static readonly object SyncLock = new object(); + private static ILogger _loggerInstance; + + internal static ILogger LoggerInstance + { + get + { + if (_loggerInstance == null) + { + lock (SyncLock) + { + _loggerInstance = InternalLogger.Create(); + } + } + + return _loggerInstance; + } + + set => _loggerInstance = value; + } /// Maximum level to log. /// E.g. set to LogLevel.Warning to have only errors and warnings in the log. diff --git a/src/IO.Ably.Tests.Shared/Realtime/DeltaSandboxSpecs.cs b/src/IO.Ably.Tests.Shared/Realtime/DeltaSandboxSpecs.cs index b3d13cb70..e18abb32b 100644 --- a/src/IO.Ably.Tests.Shared/Realtime/DeltaSandboxSpecs.cs +++ b/src/IO.Ably.Tests.Shared/Realtime/DeltaSandboxSpecs.cs @@ -231,7 +231,7 @@ public async Task WhenDeltaDecodeFail_ShouldSetStateToAttachingLogTheErrorAndDis var firstMessageReceived = new TaskCompletionAwaiter(); using (((IInternalLogger)Logger).CreateDisposableLoggingContext(testSink)) { - var realtime = await GetRealtimeClient(protocol); + var realtime = await GetRealtimeClient(protocol, (options, _) => options.LogHandler = testSink); var channel = realtime.Channels.Get(channelName, new ChannelOptions(channelParams: new ChannelParams { { "delta", "vcdiff" } })); var received = new List();