public void TestCPUUsage()
        {
            var cpuCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName);

            cpuCounter.NextValue();

            Thread.Sleep(TimeSpan.FromSeconds(2));

            // Read inital CPU usage
            var startProcessorPercent = cpuCounter.NextValue();

            // Setup writer

            var listener = new TcpListener(IPAddress.Loopback, 0);

            listener.Start();
            int port = ((IPEndPoint)listener.Server.LocalEndPoint).Port;

            var policy = new TriggeredTcpReconnectionPolicy();

            policy.Trigger();
            using (var writer = new TcpSocketWriter(IPAddress.Loopback, port, policy, 2))
            {
                Thread.Sleep(TimeSpan.FromSeconds(2));

                // Read new CPU usage value
                var newProcessorPercent = cpuCounter.NextValue();

                // Assert difference in CPU usage
                Assert.InRange(newProcessorPercent - startProcessorPercent, -5, 5);
            }
        }
        public async Task TestEventsQueuedCanBeDropped()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);

            listener.Start();
            int port = ((IPEndPoint)listener.Server.LocalEndPoint).Port;

            var policy = new TriggeredTcpReconnectionPolicy();

            policy.Trigger();
            var writer = new TcpSocketWriter(IPAddress.Loopback, port, policy, 2);

            var listenerClient = await listener.AcceptTcpClientAsync();

            listenerClient.Close();

            var errors      = new List <Exception>();
            var errorThrown = false;

            writer.LoggingFailureHandler += (ex) =>
            {
                errorThrown = true;
                errors.Add(ex);
            };

            while (!errorThrown)
            {
                writer.Enqueue("boris\r\n");
            }
            for (int i = 0; i < 10; i++)
            {
                writer.Enqueue("boris\r\n");
            }

            policy.Trigger();
            listenerClient = await listener.AcceptTcpClientAsync();

            writer.Dispose();

            var receiverReader = new StreamReader(listenerClient.GetStream());

            // Then check what was left in the queue when we disconnected
            Assert.Equal("boris", await receiverReader.ReadLineAsync());
            Assert.Equal("boris", await receiverReader.ReadLineAsync());
            Assert.Equal(0, listenerClient.Available);
        }