Skip to content
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

Add test for Rollback with pending acks #137

Merged
merged 1 commit into from
Jun 26, 2024
Merged
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
64 changes: 63 additions & 1 deletion test/ArtemisNetCoreClient.Tests/SessionSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,67 @@ await scenario.Step("Confirm that the queue is empty", async () =>
});
}

// TODO: Add test for Rollback with pending acks
[Fact]
public async Task Should_rollback_pending_acks()
{
await using var testFixture = await TestFixture.CreateAsync(testOutputHelper);
var scenario = TestScenarioFactory.Default(new XUnitOutputAdapter(testOutputHelper));

await using var connection = await testFixture.CreateConnectionAsync();
await using var session = await connection.CreateSessionAsync(new SessionConfiguration
{
AutoCommitAcks = false
}, testFixture.CancellationToken);

var (addressName, queueName) = await scenario.Step("Create address and queue", async () =>
{
var addressName = await testFixture.CreateAddressAsync(RoutingType.Anycast);
var queueName = await testFixture.CreateQueueAsync(addressName, RoutingType.Anycast);
return (addressName, queueName);
});

await using var producer = await scenario.Step("Create producer", async () =>
{
return await session.CreateProducerAsync(new ProducerConfiguration
{
Address = addressName,
RoutingType = RoutingType.Anycast
}, testFixture.CancellationToken);
});

await using var consumer = await scenario.Step("Create consumer", async () =>
{
return await session.CreateConsumerAsync(new ConsumerConfiguration
{
QueueName = queueName
}, testFixture.CancellationToken);
});

await scenario.Step("Send message", async () =>
{
await producer.SendMessageAsync(new Message
{
Body = "test_payload"u8.ToArray()
}, testFixture.CancellationToken);
});

await scenario.Step("Receive message", async () =>
{
var message = await consumer.ReceiveMessageAsync(testFixture.CancellationToken);
Assert.NotNull(message);
await consumer.AcknowledgeAsync(message.MessageDelivery, testFixture.CancellationToken);
});

await scenario.Step("Rollback transaction", async () =>
{
await session.RollbackAsync(testFixture.CancellationToken);
});

await scenario.Step("Confirm that the queue is not empty", async () =>
{
var queueInfo = await session.GetQueueInfoAsync(queueName, testFixture.CancellationToken);
Assert.NotNull(queueInfo);
Assert.Equal(1, queueInfo.MessageCount);
});
}
}
Loading