Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed Dictionary to ConcurrentDictionary #5097

Merged
merged 2 commits into from
May 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions test/Microsoft.ML.Functional.Tests/Debugging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -185,26 +186,23 @@ 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<string, int>);
Assert.Equal(1, logWatcher.Lines[line]);
}
}

internal class LogWatcher {

public readonly IDictionary<string, int> Lines;
public readonly ConcurrentDictionary<string, int> Lines;

public LogWatcher()
{
Lines = new Dictionary<string, int>();
Lines = new ConcurrentDictionary<string, int>();
}

public void ObserveEvent(object sender, LoggingEventArgs e)
sharwell marked this conversation as resolved.
Show resolved Hide resolved
{
if (Lines.ContainsKey(e.Message))
Lines[e.Message]++;
else
Lines[e.Message] = 1;
Lines.AddOrUpdate(e.Message, 1, (key, oldValue) => oldValue + 1);
}
}
}
Expand Down