1565 high cpu load from asyncsignal (#1566)

This commit is contained in:
Christian
2022-11-09 19:56:29 +01:00
committed by GitHub
parent 5c74728387
commit 5ee0bb4b65
6 changed files with 67 additions and 20 deletions
@@ -52,12 +52,26 @@ namespace MQTTnet.Tests.Internal
}
[TestMethod]
public async Task Loop_Signal()
public async Task Reset_Signal()
{
var asyncSignal = new AsyncSignal();
// WaitAsync should fail because no signal is available.
for (var i = 0; i < 10; i++)
{
try
{
using (var timeout = new CancellationTokenSource(TimeSpan.FromMilliseconds(100)))
{
await asyncSignal.WaitAsync(timeout.Token);
}
Assert.Fail("This must fail because the signal is not yet set.");
}
catch (OperationCanceledException)
{
}
asyncSignal.Set();
// WaitAsync should return directly because the signal is available.
+1 -1
View File
@@ -55,7 +55,7 @@ namespace MQTTnet.Tests.Server
});
}
SpinWait.SpinUntil(() => receivedMessages == 100000, TimeSpan.FromSeconds(90));
SpinWait.SpinUntil(() => receivedMessages == 100000, TimeSpan.FromSeconds(120));
Assert.AreEqual(100000, receivedMessages);
}
+2 -2
View File
@@ -150,7 +150,7 @@ namespace MQTTnet.Tests.Server
// Try to connect 50 clients at the same time.
var clients = await Task.WhenAll(Enumerable.Range(0, 50).Select(i => ConnectAndSubscribe(testEnvironment, options, OnReceive)));
await Task.Delay(5000);
await Task.Delay(TimeSpan.FromSeconds(10));
var connectedClients = clients.Where(c => c?.TryPingAsync().GetAwaiter().GetResult() == true).ToList();
@@ -162,7 +162,7 @@ namespace MQTTnet.Tests.Server
var sendClient = await testEnvironment.ConnectClient(option2);
await sendClient.PublishStringAsync("aaa", "1");
await Task.Delay(3000);
await Task.Delay(TimeSpan.FromSeconds(5));
Assert.AreEqual(true, hasReceive);
}