Exemple #1
0
        public void SendQueryTaskSucceed()
        {
            engine.TimeOut = TimeSpan.FromMilliseconds(25);

            Ping ping = new Ping(engine.LocalId);

            ping.TransactionId            = transactionId;
            engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e)
            {
                if (e.TimedOut)
                {
                    counter++;
                    PingResponse response = new PingResponse(node.Id, transactionId);
                    listener.RaiseMessageReceived(response, node.EndPoint);
                }
            };

            SendQueryTask task = new SendQueryTask(engine, ping, node);

            task.Completed += delegate { handle.Set(); };
            task.Execute();

#if NETSTANDARD1_5
            Assert.True(handle.WaitOne(3000), "#1");
#else
            Assert.True(handle.WaitOne(3000, false), "#1");
#endif
            System.Threading.Thread.Sleep(200);
            Assert.Equal(1, counter);
            Node n = engine.RoutingTable.FindNode(this.node.Id);
            Assert.NotNull(n);
            Assert.True(n.LastSeen > DateTime.UtcNow.AddSeconds(-2));
        }
Exemple #2
0
        public void SendPing()
        {
            engine.Add(node);
            engine.TimeOut = TimeSpan.FromMilliseconds(75);
            ManualResetEvent handle = new ManualResetEvent(false);

            engine.MessageLoop.QuerySent += delegate(object o, SendQueryEventArgs e) {
                if (!e.TimedOut && e.Query is Ping)
                {
                    handle.Set();
                }

                if (!e.TimedOut || !(e.Query is Ping))
                {
                    return;
                }

                PingResponse response = new PingResponse(node.Id, e.Query.TransactionId);
                listener.RaiseMessageReceived(response, e.EndPoint);
            };

            Assert.Equal(NodeState.Unknown, node.State);

            DateTime lastSeen = node.LastSeen;

#if NETSTANDARD1_5
            Assert.True(handle.WaitOne(1000), "#1a");
#else
            Assert.True(handle.WaitOne(1000, false), "#1a");
#endif
            Node nnnn = node;
            node = engine.RoutingTable.FindNode(nnnn.Id);
            Assert.True(lastSeen < node.LastSeen, "#2");
            Assert.Equal(NodeState.Good, node.State);
        }