Skip to content

Commit

Permalink
Handle empty Attributes for SQS GetQueueMessages (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelinag08 authored Oct 18, 2024
1 parent 95ec3fc commit 08a211d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/SnD.Sdk/Storage/Amazon/AmazonSqsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public Source<QueueElement, NotUsed> GetQueueMessages(string queueName, TimeSpan
Content = BinaryData.FromString(msg.Body),
ElementId = msg.MessageId,
DeleteHandle = msg.ReceiptHandle,
DequeueCount = long.TryParse(msg.Attributes["ApproximateReceiveCount"], out var count) ? (long?)count : null
DequeueCount = msg.Attributes.ContainsKey("ApproximateReceiveCount") && long.TryParse(msg.Attributes["ApproximateReceiveCount"], out var count)
? (long?)count
: null
});
}

Expand Down
10 changes: 5 additions & 5 deletions test/Storage/AmazonSqsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public AmazonSqsServiceTests(AkkaFixture akkaFixture, LoggerFixture loggerFixtur
}

[Theory]
[InlineData(10, 60, 10)]
[InlineData(10, 60, 1)]
[InlineData(10, 10, 1)]
public async Task GetQueueMessages1(int messagesPerCall, int visibilityTimeoutSeconds, int numCalls)
[InlineData(10, 60, 10, false)]
[InlineData(10, 60, 1, false)]
[InlineData(10, 10, 1, true)]
public async Task GetQueueMessages(int messagesPerCall, int visibilityTimeoutSeconds, int numCalls, bool emptyMessageAttributes)
{
var queueUrl = "test-queue-url";
var mockMessages = new List<Message>();
Expand All @@ -44,7 +44,7 @@ public async Task GetQueueMessages1(int messagesPerCall, int visibilityTimeoutSe
MessageId = Guid.NewGuid().ToString(),
ReceiptHandle = Guid.NewGuid().ToString(),
Body = i.ToString(),
Attributes = new Dictionary<string, string>
Attributes = emptyMessageAttributes ? new Dictionary<string, string>() : new Dictionary<string, string>
{
{ "ApproximateReceiveCount", "3" }
}
Expand Down

0 comments on commit 08a211d

Please sign in to comment.