Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove unnecessary test
  • Loading branch information
amadeuszl committed Jun 2, 2025
commit df898984dc213ec4a33f4e199007f21b5ab39782
Original file line number Diff line number Diff line change
Expand Up @@ -134,60 +134,4 @@ private LinuxNetworkMetrics CreateMetrics()
_tcpStateInfoProvider.Object,
_timeProvider);
}
[Fact]
public void GetTcpStateInfoWithRetry_Multithreaded_RetryIsThreadSafe()
{
// Arrange
var callCount = 0;
var lockObj = new object();
_tcpStateInfoProvider.Setup(p => p.GetIpV4TcpStateInfo()).Returns(() =>
{
lock (lockObj)
{
callCount++;
if (callCount == 1)
{
throw new FileNotFoundException();
}
return new TcpStateInfo { ClosedCount = 55 };
}
});

var metrics = CreateMetrics();
var results = new List<List<Measurement<long>>>();
var threads = new Thread[5];

// Act
for (int i = 0; i < threads.Length; i++)
{
threads[i] = new Thread(() =>
{
// Each thread tries to get measurements
results.Add(metrics.GetMeasurements().ToList());
});
threads[i].Start();
}
foreach (var t in threads)
{
t.Join();
}

// Advance time to after retry interval
_timeProvider.Advance(TimeSpan.FromMinutes(6));

// All threads should have received default (0) values due to retry interval
foreach (var measurementList in results)
{
Assert.All(measurementList.Take(11), m => Assert.Equal(0, m.Value));
}

// Now, after retry interval, the next call should succeed and return the new value
var afterRetry = metrics.GetMeasurements().ToList();
Assert.Equal(55, afterRetry[0].Value);
Assert.Contains(afterRetry, m => HasTagWithValue(m, "network.type", "ipv4", 55));
Assert.Contains(afterRetry, m => HasTagWithValue(m, "system.network.state", "close", 55));

// Only two calls to GetIpV4TcpStateInfo should have been made (one fail, one after retry)
_tcpStateInfoProvider.Verify(p => p.GetIpV4TcpStateInfo(), Times.Exactly(2));
}
}