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

Use SemVer #286

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0"/>
<PackageReference Include="Ductus.FluentDocker" Version="2.10.59"/>
<PackageReference Include="Semver" Version="2.3.0" />
<PackageReference Include="Polly" Version="8.2.0"/>
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1"/>
<PackageReference Include="Serilog" Version="3.1.1"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
using Ductus.FluentDocker.Builders;
using Ductus.FluentDocker.Extensions;
using Ductus.FluentDocker.Model.Builders;
using Ductus.FluentDocker.Services;
using Ductus.FluentDocker.Services.Extensions;
using Polly;
using Semver;

namespace EventStore.Client.Tests;

public class EventStoreTestServer : IEventStoreTestServer {
static readonly string ContainerName = "es-client-dotnet-test";

static Version? _version;
static SemVersion? _version;
readonly IContainerService _eventStore;
readonly string _hostCertificatePath;
readonly HttpClient _httpClient;
Expand Down Expand Up @@ -69,7 +71,7 @@ public EventStoreTestServer(
.Build();
}

public static Version Version => _version ??= GetVersion();
public static SemVersion Version => _version ??= GetVersion();

public async Task StartAsync(CancellationToken cancellationToken = default) {
_eventStore.Start();
Expand Down Expand Up @@ -99,7 +101,7 @@ public ValueTask DisposeAsync() {
return new ValueTask(Task.CompletedTask);
}

static Version GetVersion() {
static SemVersion GetVersion() {
const string versionPrefix = "EventStoreDB version";

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
Expand All @@ -111,9 +113,12 @@ static Version GetVersion() {

using var log = eventstore.Logs(true, cts.Token);
foreach (var line in log.ReadToEnd())
if (line.StartsWith(versionPrefix) &&
Version.TryParse(line[(versionPrefix.Length + 1)..].Split(' ')[0], out var version))
return version;
if (line.StartsWith(versionPrefix)) {
var versionString = line[(versionPrefix.Length + 1)..].Split(' ')[0];
if (SemVersion.TryParse(versionString, SemVersionStyles.Strict, out var version)) {
return version;
}
}

throw new InvalidOperationException("Could not determine server version.");
}
Expand Down
42 changes: 23 additions & 19 deletions test/EventStore.Client.Tests.Common/Fixtures/EventStoreFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using EventStore.Client.Tests.FluentDocker;
using Serilog;
using static System.TimeSpan;
using Semver;

namespace EventStore.Client.Tests;

Expand All @@ -24,7 +25,7 @@ this with {

public EventStoreFixtureOptions WithoutDefaultCredentials() =>
this with { ClientSettings = ClientSettings.With(x => x.DefaultCredentials = null) };

public EventStoreFixtureOptions WithMaxAppendSize(uint maxAppendSize) =>
this with { Environment = Environment.With(x => x["EVENTSTORE_MAX_APPEND_SIZE"] = $"{maxAppendSize}") };
}
Expand Down Expand Up @@ -64,12 +65,12 @@ protected EventStoreFixture(ConfigureFixture configure) {
List<Guid> TestRuns { get; } = new();

public ILogger Log => Logger;

public ITestService Service { get; }
public EventStoreFixtureOptions Options { get; }
public Faker Faker { get; } = new Faker();

public Version EventStoreVersion { get; private set; } = null!;
public SemVersion EventStoreVersion { get; private set; } = null!;
public bool EventStoreHasLastStreamPosition { get; private set; }

public EventStoreClient Streams { get; private set; } = null!;
Expand All @@ -80,7 +81,7 @@ protected EventStoreFixture(ConfigureFixture configure) {

public Func<Task> OnSetup { get; init; } = () => Task.CompletedTask;
public Func<Task> OnTearDown { get; init; } = () => Task.CompletedTask;

/// <summary>
/// must test this
/// </summary>
Expand All @@ -96,7 +97,7 @@ protected EventStoreFixture(ConfigureFixture configure) {
DefaultCredentials = Options.ClientSettings.DefaultCredentials,
DefaultDeadline = Options.ClientSettings.DefaultDeadline
};

InterlockedBoolean WarmUpCompleted { get; } = new InterlockedBoolean();
SemaphoreSlim WarmUpGatekeeper { get; } = new(1, 1);

Expand All @@ -107,15 +108,15 @@ public void CaptureTestRun(ITestOutputHelper outputHelper) {
Logger.Information(">>> Test Run {TestRunId} {Operation} <<<", testRunId, "starting");
Service.ReportStatus();
}

public async Task InitializeAsync() {
await Service.Start();

EventStoreVersion = GetEventStoreVersion();
EventStoreHasLastStreamPosition = (EventStoreVersion?.Major ?? int.MaxValue) >= 21;

await WarmUpGatekeeper.WaitAsync();

try {
if (!WarmUpCompleted.CurrentValue) {
Logger.Warning("*** Warmup started ***");
Expand All @@ -127,9 +128,9 @@ await Task.WhenAll(
InitClient<EventStorePersistentSubscriptionsClient>(async x => Subscriptions = await x.WarmUp()),
InitClient<EventStoreOperationsClient>(async x => Operations = await x.WarmUp())
);

WarmUpCompleted.EnsureCalledOnce();

Logger.Warning("*** Warmup completed ***");
}
else {
Expand All @@ -139,9 +140,9 @@ await Task.WhenAll(
finally {
WarmUpGatekeeper.Release();
}

await OnSetup();

return;

async Task<T> InitClient<T>(Func<T, Task> action, bool execute = true) where T : EventStoreClientBase {
Expand All @@ -150,9 +151,9 @@ async Task<T> InitClient<T>(Func<T, Task> action, bool execute = true) where T :
await action(client);
return client;
}
static Version GetEventStoreVersion() {


static SemVersion GetEventStoreVersion() {
const string versionPrefix = "EventStoreDB version";

using var cancellator = new CancellationTokenSource(FromSeconds(30));
Expand All @@ -165,9 +166,12 @@ static Version GetEventStoreVersion() {

using var log = eventstore.Logs(true, cancellator.Token);
foreach (var line in log.ReadToEnd())
if (line.StartsWith(versionPrefix) &&
Version.TryParse(line[(versionPrefix.Length + 1)..].Split(' ')[0], out var version))
return version;
if (line.StartsWith(versionPrefix)) {
var versionString = line[(versionPrefix.Length + 1)..].Split(' ')[0];
if (SemVersion.TryParse(versionString, SemVersionStyles.Strict, out var version)) {
return version;
}
}

throw new InvalidOperationException("Could not determine server version.");
}
Expand Down Expand Up @@ -205,4 +209,4 @@ public abstract class EventStoreTests<TFixture> : IClassFixture<TFixture> where

[Collection(nameof(EventStoreSharedDatabaseFixture))]
public abstract class EventStoreSharedDatabaseTests<TFixture>(ITestOutputHelper output, TFixture fixture) : EventStoreTests<TFixture>(output, fixture)
where TFixture : EventStoreFixture;
where TFixture : EventStoreFixture;
Loading