private async Task RemoveFromQueue(MxHostTestDetails[] messages) { foreach (MxHostTestDetails tlsTestResult in messages) { var test = tlsTestResult.Test; var hostname = test.Id; var normalizedHostname = tlsTestResult.NormalizedHostname; var messageId = test.MessageId; var receiptHandle = test.ReceiptHandle; using (_log.BeginScope(new Dictionary <string, object> { [TlsHostLogPropertyName] = hostname })) { try { if (tlsTestResult.PublishedResultsSuccessfully) { _recentlyProcessedLedger.Set(normalizedHostname); } if (tlsTestResult.PublishedResultsSuccessfully || tlsTestResult.SkipTesting) { _log.LogInformation($"Deleting message from sqs for host: {hostname} - Message Id: {messageId}"); await _mxQueueProcessor.DeleteMessage(messageId, receiptHandle); _log.LogInformation($"Deleted message from sqs for host: {hostname} - Message Id: {messageId}"); } else { _log.LogInformation($"Returning message to queue - failed to retrieve or publish results for host {hostname}"); } } catch (Exception ex) { _log.LogError(ex, $"Error occurred deleting message {test.MessageId} from queue for hostname {hostname}"); } finally { _processingFilter.ReleaseReservation(hostname); } } } }
public async Task NoProfileToProcessNoProcessingOccurs() { A.CallTo(() => _mxQueueProcessor.GetMxHosts()) .Returns(Task.FromResult(new List <TlsTestPending>())); Task process = _mxSecurityTesterProcessor.Process(cancellationTokenSource.Token); await _pipelineStartBlock.SendAsync(null); cancellationTokenSource.Cancel(); await process; A.CallTo(() => _mxQueueProcessor.GetMxHosts()).MustHaveHappenedOnceExactly(); A.CallTo(() => _mxHostTester.Test(A <TlsTestPending> ._)).MustNotHaveHappened(); A.CallTo(() => _publisher.Publish(A <Message> ._, A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _mxQueueProcessor.DeleteMessage(A <string> ._, A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _processingFilter.Reserve(A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _processingFilter.ReleaseReservation(A <string> ._)).MustNotHaveHappened(); }