Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        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");
            }
        }
Exemplo n.º 3
0
        private async Task <int> GetNumberOfMessagesToReadFromSqs()
        {
            var numberOfMessagesToReadFromSqs = Math.Min(_messageProcessingStrategy.AvailableWorkers, MessageConstants.MaxAmazonMessageCap);

            if (numberOfMessagesToReadFromSqs == 0)
            {
                await _messageProcessingStrategy.WaitForAvailableWorkers().ConfigureAwait(false);

                numberOfMessagesToReadFromSqs = Math.Min(_messageProcessingStrategy.AvailableWorkers, MessageConstants.MaxAmazonMessageCap);
            }

            if (numberOfMessagesToReadFromSqs == 0)
            {
                throw new InvalidOperationException("Cannot determine numberOfMessagesToReadFromSqs");
            }

            return(numberOfMessagesToReadFromSqs);
        }
Exemplo n.º 4
0
        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);
                }
            }
        }