Skip to content

Sync main from dev #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/handle-stale-discussions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
discussions: write
steps:
- name: Stale discussions action
uses: aws-github-ops/handle-stale-discussions@711a9813957be17629fc6933afcd8bd132c57254 #v1.6
uses: aws-github-ops/handle-stale-discussions@c0beee451a5d33d9c8f048a6d4e7c856b5422544 #v1.6.0
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
21 changes: 18 additions & 3 deletions test/AWS.Messaging.UnitTests/SQSMessagePollerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ public async Task SQSMessagePoller_PollingControlStopped_DoesNotPollSQS()
public async Task SQSMessagePoller_PollingControlRestarted_PollsSQS()
{
var client = new Mock<IAmazonSQS>();
var messageReceived = new TaskCompletionSource<bool>();
client.Setup(x => x.ReceiveMessageAsync(It.IsAny<ReceiveMessageRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new ReceiveMessageResponse(), TimeSpan.FromMilliseconds(50));
.ReturnsAsync(new ReceiveMessageResponse(), TimeSpan.FromMilliseconds(50))
.Callback(() => messageReceived.TrySetResult(true));

var pollingControlToken = new PollingControlToken
{
PollingWaitTime = TimeSpan.FromMilliseconds(25)
Expand All @@ -90,12 +93,24 @@ public async Task SQSMessagePoller_PollingControlRestarted_PollsSQS()
var pump = BuildMessagePumpService(client, options => { options.WaitTimeSeconds = 1; }, pollingControlToken: pollingControlToken);
var task = pump.StartAsync(source.Token);

// Verify no messages are received while polling is stopped
client.Verify(x => x.ReceiveMessageAsync(It.IsAny<ReceiveMessageRequest>(), It.IsAny<CancellationToken>()), Times.Never);

// Start polling and wait for a message to be received
pollingControlToken.StartPolling();

// Wait for a message to be received with a timeout
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
try
{
await messageReceived.Task.WaitAsync(cts.Token);
}
catch (OperationCanceledException)
{
Assert.Fail("Timed out waiting for message to be received after polling was restarted");
}

SpinWait.SpinUntil(() => false, pollingControlToken.PollingWaitTime * 5);

// Verify that messages were received
client.Verify(x => x.ReceiveMessageAsync(It.IsAny<ReceiveMessageRequest>(), It.IsAny<CancellationToken>()), Times.AtLeastOnce());

source.Cancel();
Expand Down