示例#1
0
    private IEnumerator WaitToSet()
    {
        yield return new WaitForSeconds(10.0f);

        TestSync[] syncObjects = FindObjectsOfType<TestSync>();
        Other = syncObjects.First(sync => sync != this);
    }
示例#2
0
        public void EnsureDrainAsync()
        {
            var subject = "5dc823d90cab46679e0bf51afffda767";
            var q       = new ConcurrentQueue <int>();

            AsyncContext.Run(async() =>
            {
                using (NATSServer.CreateFastAndVerify(Context.Server1.Port))
                {
                    using (var sync = TestSync.SingleActor())
                    {
                        var opts = Context.GetTestOptions(Context.Server1.Port);
                        opts.ClosedEventHandler = (sender, args) =>
                        {
                            q.Enqueue(1);
                            sync.SignalComplete();
                        };

                        using (var cn = Context.ConnectionFactory.CreateConnection(opts))
                        {
                            for (var i = 0; i < 50; i++)
                            {
                                cn.Publish(subject, new[] { (byte)i });
                            }

                            await cn.DrainAsync();

                            sync.WaitForAll();
                            Assert.Single(q);
                        }
                    }
                }
            });
        }
示例#3
0
        public void EnsureUnsubscribeForAsyncSub()
        {
            var subject  = "d37e3729c5c84702b836a4bb4edf7241";
            var recieved = new ConcurrentQueue <Msg>();

            AsyncContext.Run(async() =>
            {
                using (NATSServer.CreateFastAndVerify(Context.Server1.Port))
                {
                    using (var sync = TestSync.SingleActor())
                    {
                        using (var cn = Context.ConnectionFactory.CreateConnection(Context.Server1.Url))
                        {
                            using (var sub = cn.SubscribeAsync(subject, (_, m) =>
                            {
                                recieved.Enqueue(m.Message);
                                sync.SignalComplete();
                            }))
                            {
                                cn.Publish(subject, new byte[0]);
                                sync.WaitForAll();

                                sub.Unsubscribe();

                                cn.Publish(subject, new byte[0]);
                                await Task.Delay(100);
                                Assert.Equal(1, sub.Delivered);
                            }
                        }

                        Assert.Single(recieved);
                    }
                }
            });
        }
示例#4
0
        public void EnsureDrain()
        {
            var subject = "176bb0976ef943e3988de4957c9e1a1a";
            var q       = new ConcurrentQueue <int>();

            AsyncContext.Run(() =>
            {
                using (NATSServer.CreateFastAndVerify(Context.Server1.Port))
                {
                    using (var sync = TestSync.SingleActor())
                    {
                        var opts = Context.GetTestOptions(Context.Server1.Port);
                        opts.ClosedEventHandler = (sender, args) =>
                        {
                            q.Enqueue(1);
                            sync.SignalComplete();
                        };

                        using (var cn = Context.ConnectionFactory.CreateConnection(opts))
                        {
                            for (var i = 0; i < 50; i++)
                            {
                                cn.Publish(subject, new[] { (byte)i });
                            }

                            cn.Drain();

                            sync.WaitForAll();
                            Assert.Single(q);
                        }
                    }
                }
            });
        }
示例#5
0
        public void EnsurePubSubWithFlush()
        {
            var subject  = "0b122a47380145b49969ddfaafe0c206";
            var recieved = new ConcurrentQueue <Msg>();

            AsyncContext.Run(() =>
            {
                using (NATSServer.CreateFastAndVerify(Context.Server1.Port))
                {
                    using (var sync = TestSync.SingleActor())
                    {
                        using (var cn = Context.ConnectionFactory.CreateConnection(Context.Server1.Url))
                        {
                            using (cn.SubscribeAsync(subject, (_, m) =>
                            {
                                recieved.Enqueue(m.Message);
                                if (recieved.Count == 5)
                                {
                                    sync.SignalComplete();
                                }
                            }))
                            {
                                for (var i = 0; i < 5; i++)
                                {
                                    cn.Publish(subject, new[] { (byte)i });
                                    cn.Flush();
                                    cn.FlushBuffer();
                                }

                                sync.WaitForAll();
                            }
                        }

                        Assert.Equal(5, recieved.Count);
                    }
                }
            });
        }
示例#6
0
        public void EnsurePubSubWithAsyncHandler()
        {
            var subject  = "236c9af7eae044f585973503e9803f4a";
            var recieved = new ConcurrentQueue <Msg>();

            AsyncContext.Run(() =>
            {
                using (NATSServer.CreateFastAndVerify(Context.Server1.Port))
                {
                    using (var sync = TestSync.SingleActor())
                    {
                        using (var cn = Context.ConnectionFactory.CreateConnection(Context.Server1.Url))
                        {
                            using (cn.SubscribeAsync(subject, (_, m) =>
                            {
                                recieved.Enqueue(m.Message);
                                if (recieved.Count == 5)
                                {
                                    sync.SignalComplete();
                                }
                            }))
                            {
                                for (var i = 0; i < 5; i++)
                                {
                                    cn.Publish(subject, new[] { (byte)i });
                                }

                                sync.WaitForAll();
                            }
                        }

                        Assert.Equal(5, recieved.Count);
                    }
                }
            });
        }