private async Task ListenLoopExecuted(Queue <Func <Task> > actions, IMessageProcessingStrategy messageProcessingStrategy) { var initalActionCount = actions.Count; var timeoutSeconds = 10 + (initalActionCount / 100); var timeout = new TimeSpan(0, 0, timeoutSeconds); var stopwatch = Stopwatch.StartNew(); while (actions.Any()) { var batch = GetFromFakeSnsQueue(actions, messageProcessingStrategy.AvailableWorkers); foreach (var action in batch) { messageProcessingStrategy.StartWorker(action); } if (!actions.Any()) { break; } Assert.That(messageProcessingStrategy.AvailableWorkers, Is.GreaterThanOrEqualTo(0)); await messageProcessingStrategy.WaitForAvailableWorkers(); Assert.That(messageProcessingStrategy.AvailableWorkers, Is.GreaterThan(0)); if (stopwatch.Elapsed > timeout) { var message = string.Format("ListenLoopExecuted took longer than timeout of {0}s, with {1} of {2} messages remaining", timeoutSeconds, actions.Count, initalActionCount); Assert.Fail(message); } } }
private async Task ListenLoopExecuted(Queue <Func <Task> > actions, IMessageProcessingStrategy messageProcessingStrategy) { var initalActionCount = actions.Count; var timeoutSeconds = 10 + (initalActionCount / 100); var timeout = new TimeSpan(0, 0, timeoutSeconds); var stopwatch = Stopwatch.StartNew(); while (actions.Any()) { var batch = GetFromFakeSnsQueue(actions, messageProcessingStrategy.AvailableWorkers); foreach (var action in batch) { messageProcessingStrategy.StartWorker(action); } if (!actions.Any()) { break; } messageProcessingStrategy.AvailableWorkers.ShouldBeGreaterThanOrEqualTo(0); await messageProcessingStrategy.WaitForAvailableWorkers(); messageProcessingStrategy.AvailableWorkers.ShouldBeGreaterThan(0); stopwatch.Elapsed.ShouldBeLessThanOrEqualTo(timeout, $"ListenLoopExecuted took longer than timeout of {timeoutSeconds}s, with {actions.Count} of {initalActionCount} messages remaining"); } }
private void HandleMessage(Amazon.SQS.Model.Message message) { var action = new Func <Task>(() => _messageDispatcher.DispatchMessage(message)); _messageProcessingStrategy.StartWorker(action); }
private Task HandleMessage(Amazon.SQS.Model.Message message, CancellationToken ct) { var action = new Func <Task>(() => _messageDispatcher.DispatchMessage(message, ct)); return(_messageProcessingStrategy.StartWorker(action, ct)); }
private async Task ListenLoopExecuted(Queue<Func<Task>> actions, IMessageProcessingStrategy messageProcessingStrategy) { var initalActionCount = actions.Count; var timeoutSeconds = 10 + (initalActionCount / 100); var timeout = new TimeSpan(0, 0, timeoutSeconds); var stopwatch = Stopwatch.StartNew(); while (actions.Any()) { var batch = GetFromFakeSnsQueue(actions, messageProcessingStrategy.AvailableWorkers); foreach (var action in batch) { messageProcessingStrategy.StartWorker(action); } if (!actions.Any()) { break; } Assert.That(messageProcessingStrategy.AvailableWorkers, Is.GreaterThanOrEqualTo(0)); await messageProcessingStrategy.WaitForAvailableWorkers(); Assert.That(messageProcessingStrategy.AvailableWorkers, Is.GreaterThan(0)); if (stopwatch.Elapsed > timeout) { var message = string.Format("ListenLoopExecuted took longer than timeout of {0}s, with {1} of {2} messages remaining", timeoutSeconds, actions.Count, initalActionCount); Assert.Fail(message); } } }