|
| 1 | +#pragma warning disable IDE1006 // Naming Styles |
| 2 | + |
| 3 | +using FluentAssertions; |
| 4 | +using NEventStore.Persistence.AcceptanceTests.BDD; |
| 5 | + |
| 6 | +#if MSTEST |
| 7 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 8 | +#endif |
| 9 | +#if NUNIT |
| 10 | +using NUnit.Framework; |
| 11 | +#endif |
| 12 | +#if XUNIT |
| 13 | +using Xunit; |
| 14 | +#endif |
| 15 | + |
| 16 | +namespace NEventStore.Persistence.AcceptanceTests.Async |
| 17 | +{ |
| 18 | +#if MSTEST |
| 19 | + [TestClass] |
| 20 | +#endif |
| 21 | + public class when_reading_empty_async_pages_with_infinite_page_size : PersistenceEngineConcernAsync |
| 22 | + { |
| 23 | + private CommitStreamObserver? _checkpointObserver; |
| 24 | + private CommitStreamObserver? _bucketObserver; |
| 25 | + private Exception? _checkpointException; |
| 26 | + private Exception? _bucketException; |
| 27 | + |
| 28 | + protected override void Context() |
| 29 | + { |
| 30 | + Fixture!.Dispose(); |
| 31 | + Fixture.Initialize(0); |
| 32 | + } |
| 33 | + |
| 34 | + protected override async Task BecauseAsync() |
| 35 | + { |
| 36 | + _checkpointObserver = new CommitStreamObserver(); |
| 37 | + _bucketObserver = new CommitStreamObserver(); |
| 38 | + |
| 39 | + _checkpointException = await Catch.ExceptionAsync(() => |
| 40 | + ReadWithTimeout(token => Persistence.GetFromAsync(0, _checkpointObserver, token))); |
| 41 | + |
| 42 | + _bucketException = await Catch.ExceptionAsync(() => |
| 43 | + ReadWithTimeout(token => Persistence.GetFromAsync(Bucket.Default, 0, _bucketObserver, token))); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void should_complete_checkpoint_reads_without_waiting_for_another_empty_page() |
| 48 | + { |
| 49 | + _checkpointException.Should().BeNull(); |
| 50 | + _checkpointObserver!.Commits.Should().BeEmpty(); |
| 51 | + } |
| 52 | + |
| 53 | + [Fact] |
| 54 | + public void should_complete_bucket_checkpoint_reads_without_waiting_for_another_empty_page() |
| 55 | + { |
| 56 | + _bucketException.Should().BeNull(); |
| 57 | + _bucketObserver!.Commits.Should().BeEmpty(); |
| 58 | + } |
| 59 | + |
| 60 | + private static async Task ReadWithTimeout(Func<CancellationToken, Task> read) |
| 61 | + { |
| 62 | + using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(2)); |
| 63 | + await read(timeout.Token); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +#pragma warning restore IDE1006 // Naming Styles |
0 commit comments