Skip to content

Commit

Permalink
Stop using deprecated Testcontainers wait strategy
Browse files Browse the repository at this point in the history
The wait strategy `UntilOperationIsSucceeded` was deprecated in release
3.9.0:
https://github.com/testcontainers/testcontainers-dotnet/releases/tag/3.9.0

It however seems like a cleaner approach in general to simply log a
message in the end of our Groovy script to load the test graph and then
let Testcontainers wait until it sees that log.

Signed-off-by: Florian Hockmann <[email protected]>
  • Loading branch information
FlorianHockmann committed Jun 19, 2024
1 parent 1ca58ac commit a438c55
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
23 changes: 2 additions & 21 deletions test/JanusGraph.Net.IntegrationTest/JanusGraphServerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,12 @@
#endregion

using System;
using System.Net.WebSockets;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using Gremlin.Net.Driver;
using Gremlin.Net.Driver.Remote;
using JanusGraph.Net.IO.GraphSON;
using Microsoft.Extensions.Configuration;
using Xunit;
using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource;

namespace JanusGraph.Net.IntegrationTest
{
Expand All @@ -48,25 +43,11 @@ public JanusGraphServerFixture()
.WithPortBinding(JanusGraphServerPort, true)
.WithBindMount($"{AppContext.BaseDirectory}/load_data.groovy",
"/docker-entrypoint-initdb.d/load_data.groovy", AccessMode.ReadOnly)
.WithWaitStrategy(Wait.ForUnixContainer().UntilOperationIsSucceeded(IsServerReady, 1000))
.WithWaitStrategy(Wait.ForUnixContainer()
.UntilMessageIsLogged("##### Finished loading test graph #####"))
.Build();
}

private bool IsServerReady()
{
try
{
using var client = new GremlinClient(new GremlinServer(Host, Port),
new JanusGraphGraphSONMessageSerializer());
var g = Traversal().WithRemote(new DriverRemoteConnection(client));
return g.V().Has("name", "hercules").HasNext();
}
catch (AggregateException e) when (e.InnerException is WebSocketException)
{
return false;
}
}

public string Host => _container.Hostname;
public int Port => _container.GetMappedPublicPort(JanusGraphServerPort);

Expand Down
2 changes: 2 additions & 0 deletions test/JanusGraph.Net.IntegrationTest/load_data.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ g.addV('titan').property('name', 'saturn').property('age', 10000).as('saturn').
addE('pet').from('pluto').to('cerberus').
addE('lives').from('cerberus').to('tartarus').
iterate()

println '##### Finished loading test graph #####'

0 comments on commit a438c55

Please sign in to comment.