Files
MQTTnet/Tests/MQTTnet.Core.Tests/RoundtripTime_Tests.cs
T
JanEggers 14419e4d63 fixed clients overlapping from one test to another by:
- adding client and server wrappers to verify the clientid starts with the testname
- adding disposable baseclass
- clear disconnect handler from client so it does not try to reconnect after it is disposed
- moved code from dispose to cleanup in case it is called in a stop method as dispose may only be called once while start / stop may be called multiple times
2019-12-20 15:37:23 +01:00

53 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Client;
using MQTTnet.Tests.Mockups;
namespace MQTTnet.Tests
{
[TestClass]
public class RoundtripTime_Tests
{
public TestContext TestContext { get; set; }
[TestMethod]
public async Task Round_Trip_Time()
{
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
var receiverClient = await testEnvironment.ConnectClientAsync();
var senderClient = await testEnvironment.ConnectClientAsync();
await receiverClient.SubscribeAsync("#");
TaskCompletionSource<string> response = null;
receiverClient.UseApplicationMessageReceivedHandler(e =>
{
response?.SetResult(e.ApplicationMessage.ConvertPayloadToString());
});
var times = new List<TimeSpan>();
var stopwatch = Stopwatch.StartNew();
await Task.Delay(1000);
for (var i = 0; i < 100; i++)
{
response = new TaskCompletionSource<string>();
await senderClient.PublishAsync("test", DateTime.UtcNow.Ticks.ToString());
response.Task.GetAwaiter().GetResult();
stopwatch.Stop();
times.Add(stopwatch.Elapsed);
stopwatch.Restart();
}
}
}
}
}