Пример #1
0
        public async Task Ensure_Queue_Drain()
        {
            using (var testEnvironment = new TestEnvironment(TestContext))
            {
                var server = await testEnvironment.StartServer();

                var client = await testEnvironment.ConnectLowLevelClient();

                var i = 0;
                server.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(c =>
                {
                    i++;
                });

                await client.SendAsync(new MqttConnectPacket
                {
                    ClientId = "Ensure_Queue_Drain_Test"
                }, CancellationToken.None);

                await client.SendAsync(new MqttPublishPacket
                {
                    Topic = "Test"
                }, CancellationToken.None);

                await Task.Delay(500);

                // This will simulate a device which closes the connection directly
                // after sending the data so do delay is added between send and dispose!
                client.Dispose();

                await Task.Delay(1000);

                Assert.AreEqual(1, i);
            }
        }
Пример #2
0
        public async Task Loose_Connection()
        {
            using (var testEnvironment = new TestEnvironment(TestContext))
            {
                testEnvironment.ServerPort = 8364;
                var server = await testEnvironment.StartServer();

                var client = await testEnvironment.ConnectLowLevelClient(o => o.WithCommunicationTimeout(TimeSpan.Zero));

                await Authenticate(client).ConfigureAwait(false);

                await server.StopAsync();

                await Task.Delay(1000);

                try
                {
                    await client.SendAsync(MqttPingReqPacket.Instance, CancellationToken.None).ConfigureAwait(false);

                    await client.SendAsync(MqttPingReqPacket.Instance, CancellationToken.None).ConfigureAwait(false);
                }
                catch (MqttCommunicationException exception)
                {
                    Assert.IsTrue(exception.InnerException is SocketException);
                    return;
                }
                catch
                {
                    Assert.Fail("Wrong exception type thrown.");
                }

                Assert.Fail("This MUST fail");
            }
        }
Пример #3
0
        public async Task Ensure_Queue_Drain()
        {
            using (var testEnvironment = new TestEnvironment(TestContext))
            {
                var server = await testEnvironment.StartServer();

                var client = await testEnvironment.ConnectLowLevelClient();

                var i = 0;
                server.InterceptingPublishAsync += c =>
                {
                    i++;
                    return(PlatformAbstractionLayer.CompletedTask);
                };

                await client.SendAsync(
                    new MqttConnectPacket
                {
                    ClientId = "Ensure_Queue_Drain_Test"
                },
                    CancellationToken.None);

                await client.SendAsync(
                    new MqttPublishPacket
                {
                    Topic = "Test"
                },
                    CancellationToken.None);

                await Task.Delay(500);

                // This will simulate a device which closes the connection directly
                // after sending the data so do delay is added between send and dispose!
                client.Dispose();

                await Task.Delay(1000);

                Assert.AreEqual(1, i);
            }
        }