public void DisconnectDueToPingTimeout() { TestMqServer server = new TestMqServer(); server.Initialize(42105); server.Start(); TcpClient client = new TcpClient(); client.Connect("127.0.0.1", 42105); NetworkStream stream = client.GetStream(); stream.Write(PredefinedMessages.PROTOCOL_BYTES); TmqMessage msg = new TmqMessage(); msg.Type = MessageType.Server; msg.ContentType = KnownContentTypes.Hello; msg.SetStringContent("GET /\r\nName: Test-42105"); msg.CalculateLengths(); TmqWriter writer = new TmqWriter(); writer.Write(msg, stream).Wait(); Thread.Sleep(1000); Assert.Equal(1, server.ClientConnected); ThreadPool.UnsafeQueueUserWorkItem(async s => { byte[] buffer = new byte[128]; while (client.Connected) { int r = await s.ReadAsync(buffer); if (r == 0) { client.Dispose(); break; } } }, stream, false); Thread.Sleep(25000); Assert.False(client.Connected); Assert.Equal(1, server.ClientDisconnected); }