mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-29 09:52:55 +08:00
Adding delay between Pub&Sub in the test unit
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
using System;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using MQTTnet.Client;
|
||||||
|
using MQTTnet.Diagnostics;
|
||||||
|
using MQTTnet.Protocol;
|
||||||
|
using MQTTnet.Server;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
||||||
using MQTTnet.Diagnostics;
|
|
||||||
using MQTTnet.Protocol;
|
|
||||||
using MQTTnet.Server;
|
|
||||||
using MQTTnet.Client;
|
|
||||||
|
|
||||||
namespace MQTTnet.Core.Tests
|
namespace MQTTnet.Core.Tests
|
||||||
{
|
{
|
||||||
@@ -96,10 +96,11 @@ namespace MQTTnet.Core.Tests
|
|||||||
c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++;
|
c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++;
|
||||||
|
|
||||||
var message = new MqttApplicationMessageBuilder().WithTopic("a").WithAtLeastOnceQoS().Build();
|
var message = new MqttApplicationMessageBuilder().WithTopic("a").WithAtLeastOnceQoS().Build();
|
||||||
|
|
||||||
await c2.PublishAsync(message);
|
await c2.PublishAsync(message);
|
||||||
|
await Task.Delay(1000);
|
||||||
Assert.AreEqual(0, receivedMessagesCount);
|
Assert.AreEqual(0, receivedMessagesCount);
|
||||||
|
|
||||||
var subscribeEventCalled = false;
|
var subscribeEventCalled = false;
|
||||||
s.ClientSubscribedTopic += (_, e) =>
|
s.ClientSubscribedTopic += (_, e) =>
|
||||||
{
|
{
|
||||||
@@ -107,14 +108,13 @@ namespace MQTTnet.Core.Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
await c1.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce));
|
await c1.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce));
|
||||||
await Task.Delay(100);
|
await Task.Delay(500);
|
||||||
Assert.IsTrue(subscribeEventCalled, "Subscribe event not called.");
|
Assert.IsTrue(subscribeEventCalled, "Subscribe event not called.");
|
||||||
|
|
||||||
await c2.PublishAsync(message);
|
await c2.PublishAsync(message);
|
||||||
|
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
Assert.AreEqual(1, receivedMessagesCount);
|
Assert.AreEqual(1, receivedMessagesCount);
|
||||||
|
|
||||||
var unsubscribeEventCalled = false;
|
var unsubscribeEventCalled = false;
|
||||||
s.ClientUnsubscribedTopic += (_, e) =>
|
s.ClientUnsubscribedTopic += (_, e) =>
|
||||||
{
|
{
|
||||||
@@ -122,12 +122,11 @@ namespace MQTTnet.Core.Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
await c1.UnsubscribeAsync("a");
|
await c1.UnsubscribeAsync("a");
|
||||||
await Task.Delay(100);
|
await Task.Delay(500);
|
||||||
Assert.IsTrue(unsubscribeEventCalled, "Unsubscribe event not called.");
|
Assert.IsTrue(unsubscribeEventCalled, "Unsubscribe event not called.");
|
||||||
|
|
||||||
await c2.PublishAsync(message);
|
await c2.PublishAsync(message);
|
||||||
|
await Task.Delay(1000);
|
||||||
await Task.Delay(500);
|
|
||||||
Assert.AreEqual(1, receivedMessagesCount);
|
Assert.AreEqual(1, receivedMessagesCount);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -406,7 +405,7 @@ namespace MQTTnet.Core.Tests
|
|||||||
await c1.SubscribeAsync("A", MqttQualityOfServiceLevel.AtMostOnce);
|
await c1.SubscribeAsync("A", MqttQualityOfServiceLevel.AtMostOnce);
|
||||||
await c2.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("A").WithPayload(Encoding.UTF8.GetBytes("The body")).Build());
|
await c2.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("A").WithPayload(Encoding.UTF8.GetBytes("The body")).Build());
|
||||||
|
|
||||||
await Task.Delay(500);
|
await Task.Delay(1000);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user