Use lock instead of Interlocked in ObservableConcurrentHashSetTest
Related:
MODIFY
WalletWasabi.Tests/ModelTests.cs
WalletWasabi.Tests/ModelTests.cs
@@ -220,6 +220,8 @@ namespace WalletWasabi.Tests
[Fact]
public void ObservableConcurrentHashSetTest()
{
+ Set_CollectionChangedLock = new object();
+ Set_CollectionChangedInvokeCount = 0;
var set = new ObservableConcurrentHashSet<int>();
set.CollectionChanged += Set_CollectionChanged;
@@ -267,13 +269,16 @@ namespace WalletWasabi.Tests
}
}
- private long _set_CollectionChanged_InvokeCount = 0;
+ private int Set_CollectionChangedInvokeCount { get; set; }
+ private object Set_CollectionChangedLock { get; set; }
private void Set_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
- Interlocked.Increment(ref _set_CollectionChanged_InvokeCount);
+ lock (Set_CollectionChangedLock)
+ {
+ Set_CollectionChangedInvokeCount++;
- switch (Interlocked.Read(ref _set_CollectionChanged_InvokeCount))
+ switch (Set_CollectionChangedInvokeCount)
{
case 1:
{
@@ -319,3 +324,4 @@ namespace WalletWasabi.Tests
}
}
}
+}

Use lock instead of Interlocked in ObservableConcurrentHashSetTest
Related: https://github.com/zkSNACKs/WalletWasabi/issues/1276