示例#1
0
        public void Publish_should_not_throw_exception()
        {
            // warm up (establish connection)
            DummyJobWithArgs2.Publish(new DummyJobArgs2());

            using (var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
            {
                while (_performCount < 2)
                {
                    Task.Delay(100, tokenSource.Token).Wait(tokenSource.Token);
                }
            }

            var watch = Stopwatch.StartNew();

            JobBatch.Do(() =>
            {
                for (var i = 0; i < 100_000; i++)
                {
                    DummyJobWithArgs.Publish(new DummyJobArgs {
                        SomeId = i
                    });
                }
            });

            watch.Stop();

            Console.WriteLine($"Elapsed: {watch.Elapsed}");

            using (var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
            {
                while (_performCount < 100_002)
                {
                    Task.Delay(100, tokenSource.Token).Wait(tokenSource.Token);
                }
            }

            Assert.AreEqual(100_002, _performCount);
        }
示例#2
0
        public void Publish_should_not_throw_exception()
        {
            JobBatch.Do(() =>
            {
                for (var i = 0; i < 100_000; i++)
                {
                    DummyJobWithArgs.Publish(new DummyJobArgs {
                        SomeId = i
                    });
                }
            });

            DummyJobWithArgs2.Publish(new DummyJobArgs2());

            using (var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10)))
            {
                while (_performCount < 100_002)
                {
                    Task.Delay(100, tokenSource.Token).Wait();
                }
            }

            Assert.AreEqual(100_002, _performCount);
        }