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"); 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(); } }
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(); } }