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
This commit is contained in:
JanEggers
2019-12-20 15:37:23 +01:00
parent 624fafc662
commit 14419e4d63
22 changed files with 486 additions and 170 deletions
+18 -16
View File
@@ -20,10 +20,12 @@ namespace MQTTnet.Tests
[TestClass]
public class Client_Tests
{
public TestContext TestContext { get; set; }
[TestMethod]
public async Task Send_Reply_In_Message_Handler_For_Same_Client()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
var client = await testEnvironment.ConnectClientAsync();
@@ -57,7 +59,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Send_Reply_In_Message_Handler()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
var client1 = await testEnvironment.ConnectClientAsync();
@@ -89,7 +91,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Reconnect()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
var server = await testEnvironment.StartServerAsync();
var client = await testEnvironment.ConnectClientAsync();
@@ -112,7 +114,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Reconnect_While_Server_Offline()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
testEnvironment.IgnoreClientLogErrors = true;
@@ -149,7 +151,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Reconnect_From_Disconnected_Event()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
testEnvironment.IgnoreClientLogErrors = true;
@@ -189,7 +191,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task PacketIdentifier_In_Publish_Result()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
var client = await testEnvironment.ConnectClientAsync();
@@ -238,7 +240,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Fire_Disconnected_Event_On_Server_Shutdown()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
var server = await testEnvironment.StartServerAsync();
var client = await testEnvironment.ConnectClientAsync();
@@ -290,7 +292,7 @@ namespace MQTTnet.Tests
// is an issue).
const int MessagesCount = 50;
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
@@ -330,7 +332,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Send_Reply_For_Any_Received_Message()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
@@ -374,7 +376,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Publish_With_Correct_Retain_Flag()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
@@ -405,7 +407,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Subscribe_In_Callback_Events()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
@@ -444,7 +446,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Message_Send_Retry()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
testEnvironment.IgnoreClientLogErrors = true;
testEnvironment.IgnoreServerLogErrors = true;
@@ -488,7 +490,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task NoConnectedHandler_Connect_DoesNotThrowException()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
@@ -501,7 +503,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task NoDisconnectedHandler_Disconnect_DoesNotThrowException()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
var client = await testEnvironment.ConnectClientAsync();
@@ -516,7 +518,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task Frequent_Connects()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();
@@ -560,7 +562,7 @@ namespace MQTTnet.Tests
[TestMethod]
public async Task No_Payload()
{
using (var testEnvironment = new TestEnvironment())
using (var testEnvironment = new TestEnvironment(TestContext))
{
await testEnvironment.StartServerAsync();