Exemple #1
0
        void ReceiveMessages()
        {
            try {
                communicationManager.AcceptClientAsync();
                bool success = communicationManager.WaitForClientConnection(clientConnectionTimeOut);

                if (!success)
                {
                    LoggingService.LogError("Timed out waiting for client connection.");
                    OnDiscoveryFailed();
                    return;
                }
            } catch (Exception ex) {
                OnDiscoveryFailed(ex);
            }

            while (!stopping)
            {
                try {
                    Message message = communicationManager.ReceiveMessage();
                    ProcessMessage(message);
                } catch (IOException) {
                    // Ignore.
                } catch (Exception ex) {
                    LoggingService.LogError("TestPlatformAdapter receive message error.", ex);
                }
            }
        }
Exemple #2
0
        public void SocketPollShouldNotHangServerClientCommunication()
        {
            // Measure the throughput with socket communication v1 (SocketCommunicationManager)
            // implementation.
            var server = new SocketCommunicationManager();
            var client = new SocketCommunicationManager();

            int port = server.HostServer(new IPEndPoint(IPAddress.Loopback, 0)).Port;

            client.SetupClientAsync(new IPEndPoint(IPAddress.Loopback, port)).Wait();
            server.AcceptClientAsync().Wait();

            server.WaitForClientConnection(1000);
            client.WaitForServerConnection(1000);

            var clientThread = new Thread(() => SendData(client));

            clientThread.Start();

            var dataReceived = 0;

            while (dataReceived < 2048 * 5)
            {
                dataReceived += server.ReceiveRawMessageAsync(CancellationToken.None).Result.Length;
                Task.Delay(1000).Wait();
            }

            clientThread.Join();

            Assert.IsTrue(true);
        }
Exemple #3
0
        public void SocketThroughput1()
        {
            // Measure the throughput with socket communication v1 (SocketCommunicationManager)
            // implementation.
            var server = new SocketCommunicationManager();
            var client = new SocketCommunicationManager();
            var watch  = new Stopwatch();

            int port = server.HostServer(new IPEndPoint(IPAddress.Loopback, 0)).Port;

            client.SetupClientAsync(new IPEndPoint(IPAddress.Loopback, port)).Wait();
            server.AcceptClientAsync().Wait();

            server.WaitForClientConnection(1000);
            client.WaitForServerConnection(1000);

            var clientThread = new Thread(() => SendData2(client, watch));

            clientThread.Start();

            var dataReceived = 0;

            while (dataReceived < 65536 * 20000)
            {
                dataReceived += server.ReceiveRawMessage().Length;
            }

            watch.Stop();
            clientThread.Join();

            Assert.IsTrue(watch.Elapsed < TimeSpan.FromSeconds(4), "Elapsed: " + watch.Elapsed);
        }
        async Task PrivateStart()
        {
            var token = restartTokenSource.Token;

            startedSource        = new TaskCompletionSource <bool> ();
            communicationManager = new SocketCommunicationManager();
            var endPoint = communicationManager.HostServer(new IPEndPoint(IPAddress.Loopback, 0));

            communicationManager.AcceptClientAsync().Ignore();
            vsTestConsoleExeProcess = StartVsTestConsoleExe(endPoint.Port);
            vsTestConsoleExeProcess.Task.ContinueWith(delegate {
                VsTestProcessExited(vsTestConsoleExeProcess);
            }).Ignore();
            var sw = Stopwatch.StartNew();

            if (!await Task.Run(() => {
                while (!token.IsCancellationRequested)
                {
                    if (communicationManager.WaitForClientConnection(100))
                    {
                        return(true);
                    }
                    if (clientConnectionTimeOut < sw.ElapsedMilliseconds)
                    {
                        return(false);
                    }
                }
                return(false);
            }))
            {
                sw.Stop();
                throw new TimeoutException("vstest.console failed to connect.");
            }
            sw.Stop();
            if (token.IsCancellationRequested)
            {
                return;
            }

            messageProcessingThread =
                new Thread(ReceiveMessages)
            {
                IsBackground = true
            };
            messageProcessingThread.Start(token);
            var timeoutDelay = Task.Delay(clientConnectionTimeOut);

            if (await Task.WhenAny(startedSource.Task, timeoutDelay) == timeoutDelay)
            {
                throw new TimeoutException("vstest.console failed to respond.");
            }
        }