From 657236406edd99f1f84f78de0cfb5d68ccfb5330 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Tue, 23 Apr 2024 09:27:31 +0200 Subject: [PATCH 1/6] GremlinqFixture: Virtualize IAsyncLifetime methods. --- test/Tests.Fixtures/GremlinqFixture.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Tests.Fixtures/GremlinqFixture.cs b/test/Tests.Fixtures/GremlinqFixture.cs index 1cbc5a801d..6129013f15 100644 --- a/test/Tests.Fixtures/GremlinqFixture.cs +++ b/test/Tests.Fixtures/GremlinqFixture.cs @@ -58,16 +58,16 @@ private async Task GetGremlinQuerySource() return await newTcs.Task; } - else - return await GetGremlinQuerySource(); + + return await GetGremlinQuerySource(); } - public async Task InitializeAsync() + public virtual async Task InitializeAsync() { } - public async Task DisposeAsync() + public virtual async Task DisposeAsync() { if (Interlocked.Exchange(ref _lazyQuerySource, Disposed) is { } tcs && tcs != Disposed) { From c43b1981624f20f7933d5bd2cd6b827c70e0f0a4 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Tue, 23 Apr 2024 10:56:38 +0200 Subject: [PATCH 2/6] Inject fixtures everywhere. --- ...faultDebugGremlinQuerySerializationTest.cs | 6 +- .../BytecodeQuerySerializationTest.cs | 4 +- .../Graphson2GremlinQuerySerializationTest.cs | 6 +- .../Graphson3GremlinQuerySerializationTest.cs | 6 +- ...WithGroovyGremlinQuerySerializationTest.cs | 6 +- .../Serialization/OuterProjectionTest.cs | 4 +- .../NoPasswordIntegrationTests.cs | 2 +- .../WrongPasswordIntegrationTests.cs | 2 +- test/Tests.Fixtures/GremlinqFixture.cs | 78 +++++-------------- test/Tests.Fixtures/QueryExecutionTest.cs | 8 +- test/Tests.Fixtures/TestContainerFixture.cs | 6 ++ 11 files changed, 47 insertions(+), 81 deletions(-) diff --git a/test/Core.Tests/Debugging/DefaultDebugGremlinQuerySerializationTest.cs b/test/Core.Tests/Debugging/DefaultDebugGremlinQuerySerializationTest.cs index 65eab20c9b..bf7274d928 100644 --- a/test/Core.Tests/Debugging/DefaultDebugGremlinQuerySerializationTest.cs +++ b/test/Core.Tests/Debugging/DefaultDebugGremlinQuerySerializationTest.cs @@ -4,10 +4,10 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class DefaultDebugGremlinQuerySerializationTest : QueryExecutionTest + public sealed class DefaultDebugGremlinQuerySerializationTest : QueryExecutionTest, IClassFixture { - public DefaultDebugGremlinQuerySerializationTest(ITestOutputHelper testOutputHelper) : base( - GremlinqFixture.Empty, + public DefaultDebugGremlinQuerySerializationTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base( + fixture, new DebugGremlinQueryVerifier(), testOutputHelper) { diff --git a/test/Core.Tests/Serialization/BytecodeQuerySerializationTest.cs b/test/Core.Tests/Serialization/BytecodeQuerySerializationTest.cs index f1bf8573f0..b68de5903a 100644 --- a/test/Core.Tests/Serialization/BytecodeQuerySerializationTest.cs +++ b/test/Core.Tests/Serialization/BytecodeQuerySerializationTest.cs @@ -5,9 +5,9 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class BytecodeQuerySerializationTest : QueryExecutionTest + public sealed class BytecodeQuerySerializationTest : QueryExecutionTest, IClassFixture { - public BytecodeQuerySerializationTest(ITestOutputHelper testOutputHelper) : base(GremlinqFixture.Empty, new SerializingVerifier(), testOutputHelper) + public BytecodeQuerySerializationTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture, new SerializingVerifier(), testOutputHelper) { } } diff --git a/test/Core.Tests/Serialization/Graphson2GremlinQuerySerializationTest.cs b/test/Core.Tests/Serialization/Graphson2GremlinQuerySerializationTest.cs index 2e5a9b22f4..397ce332b1 100644 --- a/test/Core.Tests/Serialization/Graphson2GremlinQuerySerializationTest.cs +++ b/test/Core.Tests/Serialization/Graphson2GremlinQuerySerializationTest.cs @@ -4,12 +4,12 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class Graphson2GremlinQuerySerializationTest : QueryExecutionTest + public sealed class Graphson2GremlinQuerySerializationTest : QueryExecutionTest, IClassFixture { private static readonly GraphSON2Writer GraphSon2Writer = new (); - public Graphson2GremlinQuerySerializationTest(ITestOutputHelper testOutputHelper) : base( - GremlinqFixture.Empty, + public Graphson2GremlinQuerySerializationTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base( + fixture, new GraphSonStringSerializingVerifier(GraphSon2Writer), testOutputHelper) { diff --git a/test/Core.Tests/Serialization/Graphson3GremlinQuerySerializationTest.cs b/test/Core.Tests/Serialization/Graphson3GremlinQuerySerializationTest.cs index a9b0d8ac62..42928f8f21 100644 --- a/test/Core.Tests/Serialization/Graphson3GremlinQuerySerializationTest.cs +++ b/test/Core.Tests/Serialization/Graphson3GremlinQuerySerializationTest.cs @@ -4,12 +4,12 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class Graphson3GremlinQuerySerializationTest : QueryExecutionTest + public sealed class Graphson3GremlinQuerySerializationTest : QueryExecutionTest, IClassFixture { private static readonly GraphSON3Writer GraphSon3Writer = new (); - public Graphson3GremlinQuerySerializationTest(ITestOutputHelper testOutputHelper) : base( - GremlinqFixture.Empty, + public Graphson3GremlinQuerySerializationTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base( + fixture, new GraphSonStringSerializingVerifier(GraphSon3Writer), testOutputHelper) { diff --git a/test/Core.Tests/Serialization/Graphson3WithGroovyGremlinQuerySerializationTest.cs b/test/Core.Tests/Serialization/Graphson3WithGroovyGremlinQuerySerializationTest.cs index 4eda8448a0..1de9d720ee 100644 --- a/test/Core.Tests/Serialization/Graphson3WithGroovyGremlinQuerySerializationTest.cs +++ b/test/Core.Tests/Serialization/Graphson3WithGroovyGremlinQuerySerializationTest.cs @@ -4,12 +4,12 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class Graphson3WithGroovyGremlinQuerySerializationTest : QueryExecutionTest + public sealed class Graphson3WithGroovyGremlinQuerySerializationTest : QueryExecutionTest, IClassFixture { private static readonly GraphSON3Writer GraphSon3Writer = new(); - public Graphson3WithGroovyGremlinQuerySerializationTest(ITestOutputHelper testOutputHelper) : base( - new GroovyGremlinQuerySerializationFixture(), + public Graphson3WithGroovyGremlinQuerySerializationTest(GroovyGremlinQuerySerializationFixture fixture, ITestOutputHelper testOutputHelper) : base( + fixture, new GraphSonStringSerializingVerifier(GraphSon3Writer), testOutputHelper) { diff --git a/test/Core.Tests/Serialization/OuterProjectionTest.cs b/test/Core.Tests/Serialization/OuterProjectionTest.cs index 11d212e0bc..831802089c 100644 --- a/test/Core.Tests/Serialization/OuterProjectionTest.cs +++ b/test/Core.Tests/Serialization/OuterProjectionTest.cs @@ -5,7 +5,7 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class OuterProjectionTest : QueryExecutionTest + public sealed class OuterProjectionTest : QueryExecutionTest, IClassFixture { private sealed class ProjectionVerifier : GremlinQueryVerifier { @@ -16,7 +16,7 @@ public ProjectionVerifier(Func? settingsTaskModifier public override SettingsTask Verify(IGremlinQueryBase query) => InnerVerify(query.ToTraversal().Projection.ToTraversal(query.AsAdmin().Environment).Steps.ToArray()); } - public OuterProjectionTest(ITestOutputHelper testOutputHelper) : base(GremlinqFixture.Empty, new ProjectionVerifier(), testOutputHelper) + public OuterProjectionTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture, new ProjectionVerifier(), testOutputHelper) { } } diff --git a/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs b/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs index de9c67f6b1..acc6bc16f8 100644 --- a/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs +++ b/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs @@ -32,7 +32,7 @@ protected override async Task TransformQuerySource(IGremlin public NoPasswordIntegrationTests(NoPasswordFixture fixture) : base(new JTokenExecutingVerifier()) { - _g = fixture.GremlinQuerySource.Result; + _g = fixture.GremlinQuerySource; } [Fact(Skip = "CosmosDb often seems to close the connection right after an Authenticate status.")] diff --git a/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs b/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs index 95318847c6..a8817a8222 100644 --- a/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs +++ b/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs @@ -36,7 +36,7 @@ protected override async Task TransformQuerySource(IContain public WrongPasswordIntegrationTests(WrongPasswordGremlinServerContainerFixture fixture) : base(new JTokenExecutingVerifier()) { - _g = fixture.GremlinQuerySource.Result; + _g = fixture.GremlinQuerySource; } [Fact] diff --git a/test/Tests.Fixtures/GremlinqFixture.cs b/test/Tests.Fixtures/GremlinqFixture.cs index 6129013f15..2de4ee08cc 100644 --- a/test/Tests.Fixtures/GremlinqFixture.cs +++ b/test/Tests.Fixtures/GremlinqFixture.cs @@ -6,74 +6,38 @@ namespace ExRam.Gremlinq.Tests.Fixtures { - public abstract class GremlinqFixture : IAsyncLifetime + public sealed class EmptyGremlinqTestFixture : GremlinqFixture { - private sealed class EmptyGremlinqTestFixture : GremlinqFixture - { - protected override async Task TransformQuerySource(IGremlinQuerySource g) => g; - } - - public static readonly GremlinqFixture Empty = new EmptyGremlinqTestFixture(); - - private static readonly TaskCompletionSource Disposed = new (); - private TaskCompletionSource? _lazyQuerySource; - - static GremlinqFixture() - { - Disposed.TrySetException(new ObjectDisposedException(nameof(GremlinqFixture))); - } + protected override async Task TransformQuerySource(IGremlinQuerySource g) => g; + } + public abstract class GremlinqFixture : IAsyncLifetime + { + private IGremlinQuerySource? _gremlinQuerySource; + protected abstract Task TransformQuerySource(IGremlinQuerySource g); - public Task GremlinQuerySource => GetGremlinQuerySource(); - - private async Task GetGremlinQuerySource() - { - if (Volatile.Read(ref _lazyQuerySource) is { } tcs) - return await tcs.Task; - - var newTcs = new TaskCompletionSource(); - - if (Interlocked.CompareExchange(ref _lazyQuerySource, newTcs, null) == null) - { - try - { - var g1 = await TransformQuerySource(g - .ConfigureEnvironment(env => env - .ConfigureOptions(options => options - .SetValue(GremlinqOption.StringComparisonTranslationStrictness, StringComparisonTranslationStrictness.Lenient)))); - - newTcs.TrySetResult(g1 - .ConfigureEnvironment(env => env - .ConfigureModel(model => model == GraphModel.Invalid - ? GraphModel.FromBaseTypes() - : model))); - } - catch (Exception ex) - { - newTcs.TrySetException(ex); - - Interlocked.CompareExchange(ref _lazyQuerySource, null, newTcs); - } - - return await newTcs.Task; - } - - return await GetGremlinQuerySource(); - } + public IGremlinQuerySource GremlinQuerySource => _gremlinQuerySource ?? throw new InvalidOperationException();// GetGremlinQuerySource(); public virtual async Task InitializeAsync() { - + _gremlinQuerySource = await TransformQuerySource(g + .ConfigureEnvironment(env => env + .ConfigureOptions(options => options + .SetValue(GremlinqOption.StringComparisonTranslationStrictness, + StringComparisonTranslationStrictness.Lenient)))); + + _gremlinQuerySource = _gremlinQuerySource + .ConfigureEnvironment(env => env + .ConfigureModel(model => model == GraphModel.Invalid + ? GraphModel.FromBaseTypes() + : model)); } public virtual async Task DisposeAsync() { - if (Interlocked.Exchange(ref _lazyQuerySource, Disposed) is { } tcs && tcs != Disposed) - { - if (await tcs.Task is IAsyncDisposable disposable) - await disposable.DisposeAsync(); - } + if (_gremlinQuerySource is IAsyncDisposable disposable) + await disposable.DisposeAsync(); } } } diff --git a/test/Tests.Fixtures/QueryExecutionTest.cs b/test/Tests.Fixtures/QueryExecutionTest.cs index 29af2ace52..4e5d419dc5 100644 --- a/test/Tests.Fixtures/QueryExecutionTest.cs +++ b/test/Tests.Fixtures/QueryExecutionTest.cs @@ -18,17 +18,13 @@ public abstract class QueryExecutionTest : GremlinqTestBase { private static readonly string Id = "id"; - private readonly Lazy _lazyGremlinQuerySource; + protected readonly IGremlinQuerySource _g; protected QueryExecutionTest(GremlinqFixture fixture, GremlinQueryVerifier verifier, ITestOutputHelper testOutputHelper) : base(verifier) { - _lazyGremlinQuerySource = new Lazy( - () => fixture.GremlinQuerySource.Result, - LazyThreadSafetyMode.PublicationOnly); + _g = fixture.GremlinQuerySource; } - protected IGremlinQuerySource _g => _lazyGremlinQuerySource.Value; - [Fact] public virtual Task AddE_from_StepLabel() => _g .AddV(new Country { CountryCallingCode = "+49" }) diff --git a/test/Tests.Fixtures/TestContainerFixture.cs b/test/Tests.Fixtures/TestContainerFixture.cs index 2411f5d93a..9929534e1c 100644 --- a/test/Tests.Fixtures/TestContainerFixture.cs +++ b/test/Tests.Fixtures/TestContainerFixture.cs @@ -128,6 +128,12 @@ await container return await TransformQuerySource(container, new ContainerAttachedGremlinQuerySource(container, g)); } + public override async Task InitializeAsync() + { + await base.InitializeAsync(); + } + + protected abstract Task GetImage(); protected virtual ContainerBuilder CustomizeContainer(ContainerBuilder builder) => builder; From 7d9d04b89f6fd05f555cd41e88946c69adb214e9 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Tue, 23 Apr 2024 10:58:30 +0200 Subject: [PATCH 3/6] No EmptyGremlinqFixture. --- .../DefaultDebugGremlinQuerySerializationTest.cs | 4 ++-- .../Serialization/BytecodeQuerySerializationTest.cs | 4 ++-- .../Graphson2GremlinQuerySerializationTest.cs | 4 ++-- .../Graphson3GremlinQuerySerializationTest.cs | 4 ++-- test/Core.Tests/Serialization/OuterProjectionTest.cs | 4 ++-- test/Tests.Fixtures/GremlinqFixture.cs | 11 +++-------- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/test/Core.Tests/Debugging/DefaultDebugGremlinQuerySerializationTest.cs b/test/Core.Tests/Debugging/DefaultDebugGremlinQuerySerializationTest.cs index bf7274d928..556adcc77b 100644 --- a/test/Core.Tests/Debugging/DefaultDebugGremlinQuerySerializationTest.cs +++ b/test/Core.Tests/Debugging/DefaultDebugGremlinQuerySerializationTest.cs @@ -4,9 +4,9 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class DefaultDebugGremlinQuerySerializationTest : QueryExecutionTest, IClassFixture + public sealed class DefaultDebugGremlinQuerySerializationTest : QueryExecutionTest, IClassFixture { - public DefaultDebugGremlinQuerySerializationTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base( + public DefaultDebugGremlinQuerySerializationTest(GremlinqFixture fixture, ITestOutputHelper testOutputHelper) : base( fixture, new DebugGremlinQueryVerifier(), testOutputHelper) diff --git a/test/Core.Tests/Serialization/BytecodeQuerySerializationTest.cs b/test/Core.Tests/Serialization/BytecodeQuerySerializationTest.cs index b68de5903a..0b7c6f209d 100644 --- a/test/Core.Tests/Serialization/BytecodeQuerySerializationTest.cs +++ b/test/Core.Tests/Serialization/BytecodeQuerySerializationTest.cs @@ -5,9 +5,9 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class BytecodeQuerySerializationTest : QueryExecutionTest, IClassFixture + public sealed class BytecodeQuerySerializationTest : QueryExecutionTest, IClassFixture { - public BytecodeQuerySerializationTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture, new SerializingVerifier(), testOutputHelper) + public BytecodeQuerySerializationTest(GremlinqFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture, new SerializingVerifier(), testOutputHelper) { } } diff --git a/test/Core.Tests/Serialization/Graphson2GremlinQuerySerializationTest.cs b/test/Core.Tests/Serialization/Graphson2GremlinQuerySerializationTest.cs index 397ce332b1..ce56c7b406 100644 --- a/test/Core.Tests/Serialization/Graphson2GremlinQuerySerializationTest.cs +++ b/test/Core.Tests/Serialization/Graphson2GremlinQuerySerializationTest.cs @@ -4,11 +4,11 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class Graphson2GremlinQuerySerializationTest : QueryExecutionTest, IClassFixture + public sealed class Graphson2GremlinQuerySerializationTest : QueryExecutionTest, IClassFixture { private static readonly GraphSON2Writer GraphSon2Writer = new (); - public Graphson2GremlinQuerySerializationTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base( + public Graphson2GremlinQuerySerializationTest(GremlinqFixture fixture, ITestOutputHelper testOutputHelper) : base( fixture, new GraphSonStringSerializingVerifier(GraphSon2Writer), testOutputHelper) diff --git a/test/Core.Tests/Serialization/Graphson3GremlinQuerySerializationTest.cs b/test/Core.Tests/Serialization/Graphson3GremlinQuerySerializationTest.cs index 42928f8f21..beb16fc765 100644 --- a/test/Core.Tests/Serialization/Graphson3GremlinQuerySerializationTest.cs +++ b/test/Core.Tests/Serialization/Graphson3GremlinQuerySerializationTest.cs @@ -4,11 +4,11 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class Graphson3GremlinQuerySerializationTest : QueryExecutionTest, IClassFixture + public sealed class Graphson3GremlinQuerySerializationTest : QueryExecutionTest, IClassFixture { private static readonly GraphSON3Writer GraphSon3Writer = new (); - public Graphson3GremlinQuerySerializationTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base( + public Graphson3GremlinQuerySerializationTest(GremlinqFixture fixture, ITestOutputHelper testOutputHelper) : base( fixture, new GraphSonStringSerializingVerifier(GraphSon3Writer), testOutputHelper) diff --git a/test/Core.Tests/Serialization/OuterProjectionTest.cs b/test/Core.Tests/Serialization/OuterProjectionTest.cs index 831802089c..0c6947effc 100644 --- a/test/Core.Tests/Serialization/OuterProjectionTest.cs +++ b/test/Core.Tests/Serialization/OuterProjectionTest.cs @@ -5,7 +5,7 @@ namespace ExRam.Gremlinq.Core.Tests { - public sealed class OuterProjectionTest : QueryExecutionTest, IClassFixture + public sealed class OuterProjectionTest : QueryExecutionTest, IClassFixture { private sealed class ProjectionVerifier : GremlinQueryVerifier { @@ -16,7 +16,7 @@ public ProjectionVerifier(Func? settingsTaskModifier public override SettingsTask Verify(IGremlinQueryBase query) => InnerVerify(query.ToTraversal().Projection.ToTraversal(query.AsAdmin().Environment).Steps.ToArray()); } - public OuterProjectionTest(EmptyGremlinqTestFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture, new ProjectionVerifier(), testOutputHelper) + public OuterProjectionTest(GremlinqFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture, new ProjectionVerifier(), testOutputHelper) { } } diff --git a/test/Tests.Fixtures/GremlinqFixture.cs b/test/Tests.Fixtures/GremlinqFixture.cs index 2de4ee08cc..724337f4ac 100644 --- a/test/Tests.Fixtures/GremlinqFixture.cs +++ b/test/Tests.Fixtures/GremlinqFixture.cs @@ -6,16 +6,11 @@ namespace ExRam.Gremlinq.Tests.Fixtures { - public sealed class EmptyGremlinqTestFixture : GremlinqFixture - { - protected override async Task TransformQuerySource(IGremlinQuerySource g) => g; - } - - public abstract class GremlinqFixture : IAsyncLifetime + public class GremlinqFixture : IAsyncLifetime { private IGremlinQuerySource? _gremlinQuerySource; - - protected abstract Task TransformQuerySource(IGremlinQuerySource g); + + protected virtual async Task TransformQuerySource(IGremlinQuerySource g) => g; public IGremlinQuerySource GremlinQuerySource => _gremlinQuerySource ?? throw new InvalidOperationException();// GetGremlinQuerySource(); From 76f57baa0ff4a7cddb5310ce93cb0fe2c1482faf Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Tue, 23 Apr 2024 11:27:40 +0200 Subject: [PATCH 4/6] Move Container initialization code. --- test/Tests.Fixtures/TestContainerFixture.cs | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/Tests.Fixtures/TestContainerFixture.cs b/test/Tests.Fixtures/TestContainerFixture.cs index 9929534e1c..c087947dc5 100644 --- a/test/Tests.Fixtures/TestContainerFixture.cs +++ b/test/Tests.Fixtures/TestContainerFixture.cs @@ -105,12 +105,22 @@ async ValueTask IAsyncDisposable.DisposeAsync() private readonly int _port; + private IContainer? _container; + protected TestContainerFixtureBase(int port = 8182) { _port = port; } - protected override sealed async Task TransformQuerySource(IGremlinQuerySource g) + protected sealed override async Task TransformQuerySource(IGremlinQuerySource g) + { + if (_container is { } container) + return await TransformQuerySource(_container, new ContainerAttachedGremlinQuerySource(container, g)); + + throw new InvalidOperationException(); + } + + public override async Task InitializeAsync() { var containerBuilder = new ContainerBuilder() .WithImage(await GetImage()) @@ -119,21 +129,15 @@ protected override sealed async Task TransformQuerySource(I .ForUnixContainer() .UntilPortIsAvailable(_port)); - var container = CustomizeContainer(containerBuilder) + _container = CustomizeContainer(containerBuilder) .Build(); - await container + await _container .StartAsync(); - return await TransformQuerySource(container, new ContainerAttachedGremlinQuerySource(container, g)); - } - - public override async Task InitializeAsync() - { await base.InitializeAsync(); } - protected abstract Task GetImage(); protected virtual ContainerBuilder CustomizeContainer(ContainerBuilder builder) => builder; From 09cbeb188ff4cf31bc504e2111d4565909add587 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Tue, 23 Apr 2024 11:31:40 +0200 Subject: [PATCH 5/6] Cleanup. --- .../NoPasswordIntegrationTests.cs | 2 +- .../WrongPasswordIntegrationTests.cs | 2 +- test/Tests.Fixtures/GremlinqFixture.cs | 12 ++++++------ test/Tests.Fixtures/QueryExecutionTest.cs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs b/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs index acc6bc16f8..aee445f772 100644 --- a/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs +++ b/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs @@ -32,7 +32,7 @@ protected override async Task TransformQuerySource(IGremlin public NoPasswordIntegrationTests(NoPasswordFixture fixture) : base(new JTokenExecutingVerifier()) { - _g = fixture.GremlinQuerySource; + _g = fixture.Source; } [Fact(Skip = "CosmosDb often seems to close the connection right after an Authenticate status.")] diff --git a/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs b/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs index a8817a8222..b8699e534d 100644 --- a/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs +++ b/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs @@ -36,7 +36,7 @@ protected override async Task TransformQuerySource(IContain public WrongPasswordIntegrationTests(WrongPasswordGremlinServerContainerFixture fixture) : base(new JTokenExecutingVerifier()) { - _g = fixture.GremlinQuerySource; + _g = fixture.Source; } [Fact] diff --git a/test/Tests.Fixtures/GremlinqFixture.cs b/test/Tests.Fixtures/GremlinqFixture.cs index 724337f4ac..1f66344682 100644 --- a/test/Tests.Fixtures/GremlinqFixture.cs +++ b/test/Tests.Fixtures/GremlinqFixture.cs @@ -8,21 +8,19 @@ namespace ExRam.Gremlinq.Tests.Fixtures { public class GremlinqFixture : IAsyncLifetime { - private IGremlinQuerySource? _gremlinQuerySource; + private IGremlinQuerySource? _g; protected virtual async Task TransformQuerySource(IGremlinQuerySource g) => g; - public IGremlinQuerySource GremlinQuerySource => _gremlinQuerySource ?? throw new InvalidOperationException();// GetGremlinQuerySource(); - public virtual async Task InitializeAsync() { - _gremlinQuerySource = await TransformQuerySource(g + _g = await TransformQuerySource(g .ConfigureEnvironment(env => env .ConfigureOptions(options => options .SetValue(GremlinqOption.StringComparisonTranslationStrictness, StringComparisonTranslationStrictness.Lenient)))); - _gremlinQuerySource = _gremlinQuerySource + _g = _g .ConfigureEnvironment(env => env .ConfigureModel(model => model == GraphModel.Invalid ? GraphModel.FromBaseTypes() @@ -31,8 +29,10 @@ public virtual async Task InitializeAsync() public virtual async Task DisposeAsync() { - if (_gremlinQuerySource is IAsyncDisposable disposable) + if (_g is IAsyncDisposable disposable) await disposable.DisposeAsync(); } + + public IGremlinQuerySource Source => _g ?? throw new InvalidOperationException(); } } diff --git a/test/Tests.Fixtures/QueryExecutionTest.cs b/test/Tests.Fixtures/QueryExecutionTest.cs index 4e5d419dc5..a9cb8a9329 100644 --- a/test/Tests.Fixtures/QueryExecutionTest.cs +++ b/test/Tests.Fixtures/QueryExecutionTest.cs @@ -22,7 +22,7 @@ public abstract class QueryExecutionTest : GremlinqTestBase protected QueryExecutionTest(GremlinqFixture fixture, GremlinQueryVerifier verifier, ITestOutputHelper testOutputHelper) : base(verifier) { - _g = fixture.GremlinQuerySource; + _g = fixture.Source; } [Fact] From e2ec48744a6ee76d9283081677ea8cbc6bbdaff4 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Tue, 23 Apr 2024 11:37:25 +0200 Subject: [PATCH 6/6] TestContainerFixture: Stop container. --- .../NoPasswordIntegrationTests.cs | 2 +- .../WrongPasswordIntegrationTests.cs | 2 +- test/Tests.Fixtures/GremlinqFixture.cs | 2 +- test/Tests.Fixtures/QueryExecutionTest.cs | 2 +- test/Tests.Fixtures/TestContainerFixture.cs | 8 ++++++++ 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs b/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs index aee445f772..d91b31e66c 100644 --- a/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs +++ b/test/Providers.CosmosDb.Tests/NoPasswordIntegrationTests.cs @@ -32,7 +32,7 @@ protected override async Task TransformQuerySource(IGremlin public NoPasswordIntegrationTests(NoPasswordFixture fixture) : base(new JTokenExecutingVerifier()) { - _g = fixture.Source; + _g = fixture.G; } [Fact(Skip = "CosmosDb often seems to close the connection right after an Authenticate status.")] diff --git a/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs b/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs index b8699e534d..7879cd5325 100644 --- a/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs +++ b/test/Providers.GremlinServer.Tests/WrongPasswordIntegrationTests.cs @@ -36,7 +36,7 @@ protected override async Task TransformQuerySource(IContain public WrongPasswordIntegrationTests(WrongPasswordGremlinServerContainerFixture fixture) : base(new JTokenExecutingVerifier()) { - _g = fixture.Source; + _g = fixture.G; } [Fact] diff --git a/test/Tests.Fixtures/GremlinqFixture.cs b/test/Tests.Fixtures/GremlinqFixture.cs index 1f66344682..6476890889 100644 --- a/test/Tests.Fixtures/GremlinqFixture.cs +++ b/test/Tests.Fixtures/GremlinqFixture.cs @@ -33,6 +33,6 @@ public virtual async Task DisposeAsync() await disposable.DisposeAsync(); } - public IGremlinQuerySource Source => _g ?? throw new InvalidOperationException(); + public IGremlinQuerySource G => _g ?? throw new InvalidOperationException(); } } diff --git a/test/Tests.Fixtures/QueryExecutionTest.cs b/test/Tests.Fixtures/QueryExecutionTest.cs index a9cb8a9329..c1f0d695ad 100644 --- a/test/Tests.Fixtures/QueryExecutionTest.cs +++ b/test/Tests.Fixtures/QueryExecutionTest.cs @@ -22,7 +22,7 @@ public abstract class QueryExecutionTest : GremlinqTestBase protected QueryExecutionTest(GremlinqFixture fixture, GremlinQueryVerifier verifier, ITestOutputHelper testOutputHelper) : base(verifier) { - _g = fixture.Source; + _g = fixture.G; } [Fact] diff --git a/test/Tests.Fixtures/TestContainerFixture.cs b/test/Tests.Fixtures/TestContainerFixture.cs index c087947dc5..b18d7e4df7 100644 --- a/test/Tests.Fixtures/TestContainerFixture.cs +++ b/test/Tests.Fixtures/TestContainerFixture.cs @@ -138,6 +138,14 @@ await _container await base.InitializeAsync(); } + public override async Task DisposeAsync() + { + if (_container is { } container) + await container.StopAsync(); + + await base.DisposeAsync(); + } + protected abstract Task GetImage(); protected virtual ContainerBuilder CustomizeContainer(ContainerBuilder builder) => builder;