No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

51 líneas
1.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Threading.Tasks;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. using MQTTnet.Client;
  7. using MQTTnet.Tests.Mockups;
  8. namespace MQTTnet.Tests
  9. {
  10. [TestClass]
  11. public class RoundtripTime_Tests
  12. {
  13. [TestMethod]
  14. public async Task Round_Trip_Time()
  15. {
  16. using (var testEnvironment = new TestEnvironment())
  17. {
  18. await testEnvironment.StartServerAsync();
  19. var receiverClient = await testEnvironment.ConnectClientAsync();
  20. var senderClient = await testEnvironment.ConnectClientAsync();
  21. await receiverClient.SubscribeAsync("#");
  22. TaskCompletionSource<string> response = null;
  23. receiverClient.UseApplicationMessageReceivedHandler(e =>
  24. {
  25. response?.SetResult(e.ApplicationMessage.ConvertPayloadToString());
  26. });
  27. var times = new List<TimeSpan>();
  28. var stopwatch = Stopwatch.StartNew();
  29. await Task.Delay(1000);
  30. for (var i = 0; i < 100; i++)
  31. {
  32. response = new TaskCompletionSource<string>();
  33. await senderClient.PublishAsync("test", DateTime.UtcNow.Ticks.ToString());
  34. response.Task.GetAwaiter().GetResult();
  35. stopwatch.Stop();
  36. times.Add(stopwatch.Elapsed);
  37. stopwatch.Restart();
  38. }
  39. }
  40. }
  41. }
  42. }