private static void UseScaleout(int nodes, out MemoryHost[] hosts, out IHttpClient client) { hosts = new MemoryHost[nodes]; var eventBus = new EventBus(); var protectedData = new DefaultProtectedData(); for (var i = 0; i < nodes; ++i) { var host = new MemoryHost(); host.Configure(app => { var config = new HubConfiguration() { Resolver = new DefaultDependencyResolver() }; var bus = new DelayedMessageBus(host.InstanceName, eventBus, config.Resolver, TimeSpan.Zero); config.Resolver.Register(typeof(IMessageBus), () => bus); app.MapSignalR(config); config.Resolver.Register(typeof(IProtectedData), () => protectedData); }); hosts[i] = host; } client = new LoadBalancer(hosts); }
// This method is called by the xUnit test framework classes to run the test case. We will do the // loop here, forwarding on to the implementation in XunitTestCase to do the heavy lifting. We will // continue to re-run the test until the aggregator has an error (meaning that some internal error // condition happened), or the test runs without failure, or we've hit the maximum number of tries. public override async Task <RunSummary> RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) { var runCount = 0; while (true) { // This is really the only tricky bit: we need to capture and delay messages (since those will // contain run status) until we know we've decided to accept the final result; var delayedMessageBus = new DelayedMessageBus(messageBus); var summary = await base.RunAsync(diagnosticMessageSink, delayedMessageBus, constructorArguments, aggregator, cancellationTokenSource); if (aggregator.HasExceptions || summary.Failed == 0 || ++runCount >= maxRetries) { delayedMessageBus.Dispose(); // Sends all the delayed messages return(summary); } diagnosticMessageSink.OnMessage(new DiagnosticMessage("Execution of '{0}' failed (attempt #{1}), retrying...", DisplayName, runCount)); } }
private static async Task <RunSummary> RunTestAsyncCore(XunitTestRunner runner, IMessageBus messageBus, ExceptionAggregator aggregator, bool disableRetry) { try { DelayedMessageBus delayedMessageBus = null; RunSummary summary = null; // First run if (!disableRetry) { // This is really the only tricky bit: we need to capture and delay messages (since those will // contain run status) until we know we've decided to accept the final result; delayedMessageBus = new DelayedMessageBus(messageBus); runner.SetMessageBus(delayedMessageBus); summary = await RunTestInternalAsync(runner); // if succeeded if (summary.Failed == 0 || aggregator.HasExceptions) { delayedMessageBus.Flush(false); return(summary); } } // Final run runner.SetMessageBus(new KuduTraceMessageBus(messageBus)); summary = await RunTestInternalAsync(runner); // flush delay messages if (delayedMessageBus != null) { delayedMessageBus.Flush(summary.Failed == 0 && !aggregator.HasExceptions); } return(summary); } catch (Exception ex) { // this is catastrophic messageBus.QueueMessage(new TestFailed(runner.GetTest(), 0, null, ex)); return(new RunSummary { Failed = 1, Total = 1 }); } finally { // set to original runner.SetMessageBus(messageBus); } }
private static async Task<RunSummary> RunTestAsyncCore(XunitTestRunner runner, IMessageBus messageBus, ExceptionAggregator aggregator, bool disableRetry) { try { DelayedMessageBus delayedMessageBus = null; RunSummary summary = null; // First run if (!disableRetry) { // This is really the only tricky bit: we need to capture and delay messages (since those will // contain run status) until we know we've decided to accept the final result; delayedMessageBus = new DelayedMessageBus(messageBus); runner.SetMessageBus(delayedMessageBus); summary = await RunTestInternalAsync(runner); // if succeeded if (summary.Failed == 0 || aggregator.HasExceptions) { delayedMessageBus.Flush(false); return summary; } } // Final run runner.SetMessageBus(new KuduTraceMessageBus(messageBus)); summary = await RunTestInternalAsync(runner); // flush delay messages if (delayedMessageBus != null) { delayedMessageBus.Flush(summary.Failed == 0 && !aggregator.HasExceptions); } return summary; } catch (Exception ex) { // this is catastrophic messageBus.QueueMessage(new TestFailed(runner.GetTest(), 0, null, ex)); return new RunSummary { Failed = 1, Total = 1 }; } finally { // set to original runner.SetMessageBus(messageBus); } }
public static void Scaleout(int nodes, int clients) { var hosts = new MemoryHost[nodes]; var random = new Random(); var eventBus = new EventBus(); var protectedData = new DefaultProtectedData(); for (var i = 0; i < nodes; ++i) { var host = new MemoryHost(); host.Configure(app => { var config = new HubConfiguration() { Resolver = new DefaultDependencyResolver() }; var delay = i % 2 == 0 ? TimeSpan.Zero : TimeSpan.FromSeconds(1); var bus = new DelayedMessageBus(host.InstanceName, eventBus, config.Resolver, delay); config.Resolver.Register(typeof(IMessageBus), () => bus); app.MapSignalR(config); config.Resolver.Register(typeof(IProtectedData), () => protectedData); }); hosts[i] = host; } var client = new LoadBalancer(hosts); var wh = new ManualResetEventSlim(); for (int i = 0; i < clients; i++) { Task.Run(() => RunLoop(client, wh)); } wh.Wait(); }
// This method is called by the xUnit test framework classes to run the test case. We will do the // loop here, forwarding on to the implementation in XunitTestCase to do the heavy lifting. We will // continue to re-run the test until the aggregator has an error (meaning that some internal error // condition happened), or the test runs without failure, or we've hit the maximum number of tries. public override async Task<RunSummary> RunAsync(IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) { var runCount = 0; while (true) { // This is really the only tricky bit: we need to capture and delay messages (since those will // contain run status) until we know we've decided to accept the final result; var delayedMessageBus = new DelayedMessageBus(messageBus); var summary = await base.RunAsync(diagnosticMessageSink, delayedMessageBus, constructorArguments, aggregator, cancellationTokenSource); if (aggregator.HasExceptions || summary.Failed == 0 || ++runCount >= maxRetries) { delayedMessageBus.Dispose(); // Sends all the delayed messages return summary; } diagnosticMessageSink.OnMessage(new DiagnosticMessage("Execution of '{0}' failed (attempt #{1}), retrying...", DisplayName, runCount)); } }
public static async Task <RunSummary> RunTestAsync(XunitTestRunner runner, IMessageBus messageBus, ExceptionAggregator aggregator, bool disableRetry) { // defense in depth to avoid forever lock bool acquired = await _semaphore.WaitAsync(TimeSpan.FromHours(2)); try { DelayedMessageBus delayedMessageBus = null; RunSummary summary = null; if (!acquired) { throw new TimeoutException("Wait for thread to run the test timeout!"); } // First run if (!disableRetry) { // This is really the only tricky bit: we need to capture and delay messages (since those will // contain run status) until we know we've decided to accept the final result; delayedMessageBus = new DelayedMessageBus(messageBus); runner.SetMessageBus(delayedMessageBus); summary = await RunTestInternalAsync(runner); // if succeeded if (summary.Failed == 0 || aggregator.HasExceptions) { delayedMessageBus.Flush(false); return(summary); } } // Final run runner.SetMessageBus(new KuduTraceMessageBus(messageBus)); summary = await RunTestInternalAsync(runner); // flush delay messages if (delayedMessageBus != null) { delayedMessageBus.Flush(summary.Failed == 0 && !aggregator.HasExceptions); } return(summary); } catch (Exception ex) { // this is catastrophic messageBus.QueueMessage(new TestFailed(runner.GetTest(), 0, null, ex)); return(new RunSummary { Failed = 1, Total = 1 }); } finally { if (acquired) { _semaphore.Release(); } // set to original runner.SetMessageBus(messageBus); } }
public static void Scaleout(int nodes, int clients) { var hosts = new MemoryHost[nodes]; var random = new Random(); var eventBus = new EventBus(); for (var i = 0; i < nodes; ++i) { var host = new MemoryHost(); host.Configure(app => { var config = new HubConfiguration() { Resolver = new DefaultDependencyResolver() }; var delay = i % 2 == 0 ? TimeSpan.Zero : TimeSpan.FromSeconds(1); var bus = new DelayedMessageBus(host.InstanceName, eventBus, config.Resolver, delay); config.Resolver.Register(typeof(IMessageBus), () => bus); app.MapHubs(config); }); hosts[i] = host; } var client = new LoadBalancer(hosts); var wh = new ManualResetEventSlim(); for (int i = 0; i < clients; i++) { Task.Run(() => RunLoop(client, wh)); } wh.Wait(); }
public static async Task<RunSummary> RunTestAsync(XunitTestRunner runner, IMessageBus messageBus, ExceptionAggregator aggregator, bool disableRetry) { // defense in depth to avoid forever lock bool acquired = await _semaphore.WaitAsync(TimeSpan.FromHours(2)); try { DelayedMessageBus delayedMessageBus = null; RunSummary summary = null; if (!acquired) { throw new TimeoutException("Wait for thread to run the test timeout!"); } // First run if (!disableRetry) { // This is really the only tricky bit: we need to capture and delay messages (since those will // contain run status) until we know we've decided to accept the final result; delayedMessageBus = new DelayedMessageBus(messageBus); runner.SetMessageBus(delayedMessageBus); summary = await RunTestInternalAsync(runner); // if succeeded if (summary.Failed == 0 || aggregator.HasExceptions) { delayedMessageBus.Flush(false); return summary; } } // Final run runner.SetMessageBus(new KuduTraceMessageBus(messageBus)); summary = await RunTestInternalAsync(runner); // flush delay messages if (delayedMessageBus != null) { delayedMessageBus.Flush(summary.Failed == 0 && !aggregator.HasExceptions); } return summary; } catch (Exception ex) { // this is catastrophic messageBus.QueueMessage(new TestFailed(runner.GetTest(), 0, null, ex)); return new RunSummary { Failed = 1, Total = 1 }; } finally { if (acquired) { _semaphore.Release(); } // set to original runner.SetMessageBus(messageBus); } }
private static void UseScaleout(int nodes, out MemoryHost[] hosts, out IHttpClient client) { hosts = new MemoryHost[nodes]; var eventBus = new EventBus(); for (var i = 0; i < nodes; ++i) { var host = new MemoryHost(); host.Configure(app => { var config = new HubConfiguration() { Resolver = new DefaultDependencyResolver() }; var bus = new DelayedMessageBus(host.InstanceName, eventBus, config.Resolver, TimeSpan.Zero); config.Resolver.Register(typeof(IMessageBus), () => bus); app.MapHubs(config); }); hosts[i] = host; } client = new LoadBalancer(hosts); }