Пример #1
0
        public static void StressGroups()
        {
            var host = new MemoryHost();

            host.MapHubs();
            int max = 15;

            var countDown  = new CountDown(max);
            var list       = Enumerable.Range(0, max).ToList();
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy      = connection.CreateProxy("MultGroupHub");

            proxy.On <int>("Do", i =>
            {
                lock (list)
                {
                    if (!list.Remove(i))
                    {
                        Debugger.Break();
                    }
                }

                countDown.Dec();
            });

            try
            {
                connection.Start(host).Wait();

                for (int i = 0; i < max; i++)
                {
                    proxy.Invoke("Do", i).Wait();
                }

                if (!countDown.Wait(TimeSpan.FromSeconds(10)))
                {
                    Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed (" + String.Join(",", list.Select(i => i.ToString())) + ")");
                    var bus = host.DependencyResolver.Resolve <INewMessageBus>();
                    Debugger.Break();
                }
            }
            finally
            {
                connection.Stop();
                host.Dispose();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Пример #2
0
        public static void StressGroups()
        {
            var host = new MemoryHost();
            host.HubPipeline.EnableAutoRejoiningGroups();
            host.MapHubs();
            int max = 15;

            var countDown = new CountDown(max);
            var list = Enumerable.Range(0, max).ToList();
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("MultGroupHub");

            var bus = (MessageBus)host.DependencyResolver.Resolve<IMessageBus>();

            proxy.On<int>("Do", i =>
            {
                lock (list)
                {
                    if (!list.Remove(i))
                    {
                        Debugger.Break();
                    }
                }

                countDown.Dec();
            });

            try
            {
                connection.Start(host).Wait();

                for (int i = 0; i < max; i++)
                {
                    proxy.Invoke("Do", i).Wait();
                }

                int retry = 3;
                bool result = false;

                do
                {
                    result = countDown.Wait(TimeSpan.FromSeconds(10));
                    if (!result)
                    {
                        Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed (" + String.Join(",", list.Select(i => i.ToString())) + ")");
                        Console.WriteLine("A=" + bus.AllocatedWorkers + " B=" + bus.BusyWorkers);
                        countDown.Reset();
                    }

                    retry--;

                } while (retry > 0);

                if (!result)
                {
                    Console.WriteLine("A=" + bus.AllocatedWorkers + " B=" + bus.BusyWorkers);
                    Debugger.Break();
                }
            }
            finally
            {
                connection.Stop();
                host.Dispose();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Пример #3
0
        public static void StressGroups()
        {
            var host = new MemoryHost();
            host.MapHubs();
            int max = 15;

            var countDown = new CountDown(max);
            var list = Enumerable.Range(0, max).ToList();
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy = connection.CreateProxy("MultGroupHub");

            proxy.On<int>("Do", i =>
            {
                lock (list)
                {
                    if (!list.Remove(i))
                    {
                        Debugger.Break();
                    }
                }

                countDown.Dec();
            });

            try
            {
                connection.Start(new Client.Transports.ServerSentEventsTransport(host)).Wait();

                for (int i = 0; i < max; i++)
                {
                    proxy.Invoke("Do", i).Wait();
                }

                if (!countDown.Wait(TimeSpan.FromSeconds(10)))
                {
                    Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed (" + String.Join(",", list.Select(i => i.ToString())) + ")");
                    var bus = host.DependencyResolver.Resolve<INewMessageBus>();
                    Debugger.Break();
                }
            }
            finally
            {
                connection.Stop();
                host.Dispose();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Пример #4
0
        public static void StressGroups()
        {
            var host = new MemoryHost();

            host.HubPipeline.EnableAutoRejoiningGroups();
            host.MapHubs();
            int max = 15;

            var countDown  = new CountDown(max);
            var list       = Enumerable.Range(0, max).ToList();
            var connection = new Client.Hubs.HubConnection("http://foo");
            var proxy      = connection.CreateProxy("MultGroupHub");

            var bus = (MessageBus)host.DependencyResolver.Resolve <IMessageBus>();

            proxy.On <int>("Do", i =>
            {
                lock (list)
                {
                    if (!list.Remove(i))
                    {
                        Debugger.Break();
                    }
                }

                countDown.Dec();
            });

            try
            {
                connection.Start(host).Wait();

                for (int i = 0; i < max; i++)
                {
                    proxy.Invoke("Do", i).Wait();
                }

                int  retry  = 3;
                bool result = false;

                do
                {
                    result = countDown.Wait(TimeSpan.FromSeconds(10));
                    if (!result)
                    {
                        Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed (" + String.Join(",", list.Select(i => i.ToString())) + ")");
                        Console.WriteLine("A=" + bus.AllocatedWorkers + " B=" + bus.BusyWorkers);
                        countDown.Reset();
                    }

                    retry--;
                } while (retry > 0);

                if (!result)
                {
                    Console.WriteLine("A=" + bus.AllocatedWorkers + " B=" + bus.BusyWorkers);
                    Debugger.Break();
                }
            }
            finally
            {
                connection.Stop();
                host.Dispose();

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }