From a3a8233d94b0e5695dba51aca3534c027443ecff Mon Sep 17 00:00:00 2001 From: "Harish S. Kulkarni" Date: Wed, 6 May 2020 13:00:00 -0700 Subject: [PATCH 1/2] Changed Dictionary to ConcurrentDictionary --- test/Microsoft.ML.Functional.Tests/Debugging.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.ML.Functional.Tests/Debugging.cs b/test/Microsoft.ML.Functional.Tests/Debugging.cs index eaf0a0135c..0c2e4fa467 100644 --- a/test/Microsoft.ML.Functional.Tests/Debugging.cs +++ b/test/Microsoft.ML.Functional.Tests/Debugging.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Collections.Concurrent; using System.Collections.Generic; using Microsoft.ML.Data; using Microsoft.ML.Functional.Tests.Datasets; @@ -196,7 +197,7 @@ internal class LogWatcher { public LogWatcher() { - Lines = new Dictionary(); + Lines = new ConcurrentDictionary(); } public void ObserveEvent(object sender, LoggingEventArgs e) From 59f11078478fccc0655c9cdfd28bcdaaaa0309df Mon Sep 17 00:00:00 2001 From: "Harish S. Kulkarni" Date: Wed, 6 May 2020 14:33:26 -0700 Subject: [PATCH 2/2] Changed to use AddOrUpdate --- test/Microsoft.ML.Functional.Tests/Debugging.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/Microsoft.ML.Functional.Tests/Debugging.cs b/test/Microsoft.ML.Functional.Tests/Debugging.cs index 0c2e4fa467..b58433e157 100644 --- a/test/Microsoft.ML.Functional.Tests/Debugging.cs +++ b/test/Microsoft.ML.Functional.Tests/Debugging.cs @@ -186,14 +186,14 @@ public void ViewTrainingOutput() @"[Source=SdcaTrainerBase; Training, Kind=Info] Using best model from iteration 7."}; foreach (var line in expectedLines) { - Assert.Contains(line, logWatcher.Lines); + Assert.Contains(line, logWatcher.Lines as IReadOnlyDictionary); Assert.Equal(1, logWatcher.Lines[line]); } } internal class LogWatcher { - public readonly IDictionary Lines; + public readonly ConcurrentDictionary Lines; public LogWatcher() { @@ -202,10 +202,7 @@ public LogWatcher() public void ObserveEvent(object sender, LoggingEventArgs e) { - if (Lines.ContainsKey(e.Message)) - Lines[e.Message]++; - else - Lines[e.Message] = 1; + Lines.AddOrUpdate(e.Message, 1, (key, oldValue) => oldValue + 1); } } }