Skip to content

Commit f29e700

Browse files
committed
Update locking mechanism and tests to verify locks
1 parent d557101 commit f29e700

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Common/Commands.Common/MetricHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
using System;
2323
using System.Collections.Generic;
2424
using System.Diagnostics;
25-
using System.Linq;
26-
using System.Net.NetworkInformation;
2725
using System.Security.Cryptography;
2826
using System.Text;
2927

@@ -62,7 +60,7 @@ public string HashMacAddress
6260
{
6361
get
6462
{
65-
lock(_hashMacAddress)
63+
lock(_lock)
6664
{
6765
if (_hashMacAddress == string.Empty)
6866
{

src/ResourceManager/Profile/Commands.Profile.Test/TelemetryTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public void HashofNullNetworkMACAddressIsNull()
4848
metricHelper.HashMacAddress = string.Empty;
4949
try
5050
{
51+
// verify that initialization happens only once and
52+
// there are no issues with retrieving the value
53+
Assert.Null(metricHelper.HashMacAddress);
5154
Assert.Null(metricHelper.HashMacAddress);
5255
helper.Verify((f) => f.GetMACAddress(), Times.Once);
5356
}
@@ -67,6 +70,7 @@ public void HashofEmptyNetworkMACAddressIsNull()
6770
metricHelper.HashMacAddress = string.Empty;
6871
try
6972
{
73+
Assert.Null(metricHelper.HashMacAddress);
7074
Assert.Null(metricHelper.HashMacAddress);
7175
helper.Verify((f) => f.GetMACAddress(), Times.Once);
7276
}
@@ -86,6 +90,7 @@ public void HashMacAddressOnThrowIsNull()
8690
metricHelper.HashMacAddress = string.Empty;
8791
try
8892
{
93+
Assert.Null(metricHelper.HashMacAddress);
8994
Assert.Null(metricHelper.HashMacAddress);
9095
helper.Verify((f) => f.GetMACAddress(), Times.Once);
9196
}

0 commit comments

Comments
 (0)