private void OnClientDisconnected(object sender, SmartSocketClient e)
 {
     lock (this.SchedulerLock)
     {
         this.TestingProcessChannels.Remove(e.Name);
     }
 }
        private async void HandleClient(SmartSocketClient e)
        {
            this.WriteLine("Client connected: " + e.Name);
            this.LastEvent = DateTime.Now;

            while (e.IsConnected && this.Telemetry != null)
            {
                try
                {
                    var msg = await e.ReceiveAsync();

                    if (msg != null)
                    {
                        this.LastEvent = DateTime.Now;
                        if (msg is TelemetryEvent tm)
                        {
                            this.HandleTelemetry(tm);
                        }
                        else if (msg is TelemetryMetric metric)
                        {
                            this.HandleMetric(metric);
                        }
                        else
                        {
                            this.WriteLine("Received heartbeat");
                        }

                        await e.SendAsync(new SocketMessage("ok", TelemetryServerEndPoint));
                    }
                }
                catch (Exception)
                {
                }
            }
        }
        private void OnClientError(object sender, Exception e)
        {
            // todo: handle client failures?  The client process died, etc...
            SmartSocketClient client = (SmartSocketClient)sender;

            if (!this.Terminating.Contains(client.Name))
            {
                Console.WriteLine($"### Error from client {client.Name}: {e.Message}");
            }
        }
        private void OnClientConnected(object sender, SmartSocketClient e)
        {
            e.Error += this.OnClientError;

            if (this.IsVerbose)
            {
                Console.WriteLine($"... TestProcess '{e.Name}' is connected");
            }

            Task.Run(() => this.HandleClientAsync(e));
        }
        private async void HandleBackChannel(SmartSocketClient server)
        {
            while (!this.Terminating && server.IsConnected)
            {
                var msg = await server.ReceiveAsync();

                if (msg is TestServerMessage)
                {
                    this.HandleServerMessage((TestServerMessage)msg);
                }
            }
        }
Beispiel #6
0
        private async void OnBackChannelOpened(object sender, SmartSocketClient e)
        {
            Console.WriteLine("OnBackChannelOpened '{0}'", e.Name);
            for (int i = 0; i < 10; i++)
            {
                var response = await e.BackChannel.SendReceiveAsync(new SocketMessage("BackChannelRequest", Name) { Message = "backchannel request" });

                if (response != null)
                {
                    Console.WriteLine("Response from client is: " + response.Id);
                }
            }
        }
Beispiel #7
0
        private async void HandleBackChannel(SmartSocketClient server)
        {
            CancellationToken token = this.source.Token;

            while (!token.IsCancellationRequested && server.IsConnected)
            {
                var msg = await server.ReceiveAsync();

                if (msg != null)
                {
                    backChannelMessages++;
                    Console.WriteLine("Client received backchannel message from server '{0}': {1}", msg.Sender, msg.Id);
                    await server.SendAsync(new SocketMessage("Backchannel message received", this.name) { Message = msg.Message });
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Opens the remote notification listener. If this is
        /// not a parallel testing process, then this operation
        /// does nothing.
        /// </summary>
        private async Task ConnectToServer()
        {
            string serviceName = this.Configuration.TestingSchedulerEndPoint;
            var    source      = new System.Threading.CancellationTokenSource();

            var resolver = new SmartSocketTypeResolver(typeof(BugFoundMessage),
                                                       typeof(TestReportMessage),
                                                       typeof(TestServerMessage),
                                                       typeof(TestProgressMessage),
                                                       typeof(TestTraceMessage),
                                                       typeof(TestReport),
                                                       typeof(CoverageInfo),
                                                       typeof(Configuration));

            SmartSocketClient client = null;

            if (!string.IsNullOrEmpty(this.Configuration.TestingSchedulerIpAddress))
            {
                string[] parts = this.Configuration.TestingSchedulerIpAddress.Split(':');
                if (parts.Length == 2)
                {
                    var endPoint = new IPEndPoint(IPAddress.Parse(parts[0]), int.Parse(parts[1]));
                    while (!source.IsCancellationRequested && client == null)
                    {
                        client = await SmartSocketClient.ConnectAsync(endPoint, this.Name, resolver);
                    }
                }
            }
            else
            {
                client = await SmartSocketClient.FindServerAsync(serviceName, this.Name, resolver, source.Token);
            }

            if (client == null)
            {
                throw new Exception("Failed to connect to server");
            }

            client.Error     += this.OnClientError;
            client.ServerName = serviceName;
            this.Server       = client;

            // open back channel so server can also send messages to us any time.
            await client.OpenBackChannel(this.OnBackChannelConnected);
        }
Beispiel #9
0
        private async void HandleClientAsync(SmartSocketClient client)
        {
            while (client.IsConnected)
            {
                ClientMessage e = await client.ReceiveAsync() as ClientMessage;

                if (e != null)
                {
                    if (e.Id == "test")
                    {
                        await client.SendAsync(new ServerMessage("test", Name, DateTime.Now));
                    }
                    else
                    {
                        Console.WriteLine("Received message '{0}' from '{1}' at '{2}'", e.Id, e.Sender, e.Timestamp);
                        await client.SendAsync(new ServerMessage("Server says hi!", Name, DateTime.Now));
                    }
                }
            }
        }
Beispiel #10
0
        private async Task RunTest()
        {
            this.source = new CancellationTokenSource();
            using (SmartSocketClient client = await SmartSocketClient.FindServerAsync("TestServer", name, new SmartSocketTypeResolver(typeof(ServerMessage), typeof(ClientMessage)), source.Token))
            {
                client.Error += OnClientError;

                for (int i = 0; i < 10; i++)
                {
                    SocketMessage response = await client.SendReceiveAsync(new ClientMessage("Howdy partner " + i, this.name, DateTime.Now));

                    ServerMessage e = (ServerMessage)response;
                    Console.WriteLine("Client Received message '{0}' from '{1}' at '{2}'", e.Id, e.Sender, e.Timestamp);
                }

                Stopwatch watch = new Stopwatch();
                watch.Start();
                for (int i = 0; i < 1000; i++)
                {
                    SocketMessage response = await client.SendReceiveAsync(new ClientMessage("test", this.name, DateTime.Now));

                    ServerMessage e = (ServerMessage)response;
                    // todo: do something with the server response.
                }
                watch.Stop();

                Console.WriteLine("Sent 1000 messages in {0} milliseconds", watch.ElapsedMilliseconds);

                var server = await client.OpenBackChannel(OnBackChannelOpened);

                while (backChannelMessages < 10)
                {
                    await Task.Delay(10);
                }
            }
            this.source.Cancel();
        }
        private async void OnBackChannelOpened(object sender, SmartSocketClient e)
        {
            // this is the socket we can use to communicate directly to the client... it will be
            // available as the "BackChannel" property on the associated client socket.
            // But if we've already asked this client to terminate then tell it to stop.
            SocketMessage     response = new TestServerMessage("ok", this.Configuration.TestingSchedulerEndPoint);
            TestServerMessage message  = null;

            lock (this.Terminating)
            {
                if (this.Terminating.Contains(e.Name))
                {
                    message = new TestServerMessage("ok", this.Configuration.TestingSchedulerEndPoint)
                    {
                        Stop = true
                    };
                }
            }

            if (message != null)
            {
                await e.BackChannel.SendAsync(message);
            }
        }
Beispiel #12
0
 private void OnBackChannelConnected(object sender, SmartSocketClient e)
 {
     Task.Run(() => this.HandleBackChannel(e));
 }
Beispiel #13
0
 private void OnBackChannelOpened(object sender, SmartSocketClient e)
 {
     _ = Task.Run(() => HandleBackChannel(e));
 }
        private async void HandleClientAsync(SmartSocketClient client)
        {
            while (client.IsConnected)
            {
                SocketMessage e = await client.ReceiveAsync();

                if (e != null)
                {
                    this.LastMessageTime = Environment.TickCount;
                    uint processId = 0;

                    if (e.Id == SmartSocketClient.ConnectedMessageId)
                    {
                        lock (this.SchedulerLock)
                        {
                            this.TestProcessesConnected++;
                            this.TestingProcessChannels.Add(e.Sender, client);
                        }
                    }
                    else if (e is BugFoundMessage)
                    {
                        BugFoundMessage bug = (BugFoundMessage)e;
                        processId = bug.ProcessId;
                        await client.SendAsync(new SocketMessage("ok", this.Configuration.TestingSchedulerEndPoint));

                        if (this.IsVerbose)
                        {
                            Console.WriteLine($"... Bug report received from '{bug.Sender}'");
                        }

                        this.NotifyBugFound(processId);
                    }
                    else if (e is TestReportMessage)
                    {
                        TestReportMessage report = (TestReportMessage)e;
                        processId = report.ProcessId;
                        await client.SendAsync(new SocketMessage("ok", this.Configuration.TestingSchedulerEndPoint));

                        if (this.IsVerbose)
                        {
                            Console.WriteLine($"... Test report received from '{report.Sender}'");
                        }

                        this.SetTestReport(report.TestReport, report.ProcessId);
                    }
                    else if (e is TestTraceMessage)
                    {
                        TestTraceMessage report = (TestTraceMessage)e;
                        processId = report.ProcessId;
                        await client.SendAsync(new SocketMessage("ok", this.Configuration.TestingSchedulerEndPoint));

                        this.SaveTraceReport(report);
                    }
                    else if (e is TestProgressMessage)
                    {
                        TestProgressMessage progress = (TestProgressMessage)e;
                        processId = progress.ProcessId;
                        await client.SendAsync(new SocketMessage("ok", this.Configuration.TestingSchedulerEndPoint));

                        // todo: do something fun with progress info.
                    }
                }
            }
        }
 /// <summary>
 /// Called when a separate coyote test/replay process termiantes.
 /// </summary>
 private void OnClientDisconnected(object sender, SmartSocketClient e)
 {
     this.WriteLine("Client disconnected: " + e.Name);
 }
 /// <summary>
 /// Called when a separate coyote test/replay process starts up and connects to
 /// this server.
 /// </summary>
 private void OnClientConnected(object sender, SmartSocketClient e)
 {
     // A coyote process has started up, so this socket will be used to receive telemetry requests.
     Task.Run(() => this.HandleClient(e));
 }
Beispiel #17
0
 private void OnClientDisconnected(object sender, SmartSocketClient e)
 {
     Console.WriteLine("Client '{0}' has gone bye bye...", e.Name);
 }
Beispiel #18
0
        /// <summary>
        /// Starts a telemetry server in a separate coyote process.
        /// </summary>
        private async Task ConnectToServer(string serverPath)
        {
            this.FindServerTokenSource = new CancellationTokenSource();
            var token = this.FindServerTokenSource.Token;

            string serviceName = CoyoteTelemetryServer.TelemetryServerEndPoint;
            var    resolver    = new SmartSocketTypeResolver(typeof(TelemetryEvent), typeof(TelemetryMetric));

            SmartSocketClient client = null;
            var findTask             = SmartSocketClient.FindServerAsync(serviceName, this.Name, resolver, token,
                                                                         CoyoteTelemetryServer.UdpGroupAddress, CoyoteTelemetryServer.UdpGroupPort);

            try
            {
                if (findTask.Wait(1000, token))
                {
                    client = findTask.Result;
                }
            }
            catch
            {
                // timeout or cancelled.
                if (token.IsCancellationRequested)
                {
                    return;
                }
            }

            if (client is null)
            {
                try
                {
                    StartServer(serverPath);
                    client = await SmartSocketClient.FindServerAsync(serviceName, this.Name, resolver, token,
                                                                     CoyoteTelemetryServer.UdpGroupAddress, CoyoteTelemetryServer.UdpGroupPort);
                }
                catch
                {
                    // failed to connect to new telemetry server
                    this.Enabled = false;
                    return;
                }
            }

            client.Error     += this.OnClientError;
            client.ServerName = serviceName;
            this.Server       = client;

            // send any pending queue of stuff.
            List <SocketMessage> pending = null;

            lock (this.Pending)
            {
                pending      = this.Pending;
                this.Pending = null;
            }

            foreach (var e in pending)
            {
                await this.Server.SendReceiveAsync(e);
            }

            this.PendingCleared.Set();

            _ = Task.Run(this.SendHeartbeats);
        }
Beispiel #19
0
 private void OnClientConnected(object sender, SmartSocketClient e)
 {
     e.Error += OnClientError;
     Console.WriteLine("Client '{0}' is connected", e.Name);
     Task.Run(() => HandleClientAsync(e));
 }