Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
w1am committed Jan 7, 2025
1 parent f68cec0 commit 7699152
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 156 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@ on:
required: false
type: string
default: eventstore-ce/eventstoredb-ce
# test:
# required: true
# type: string

jobs:
test:
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
framework: [ net9.0 ]
framework: [ net8.0, net9.0 ]
os: [ ubuntu-latest ]
configuration: [ release ]
runs-on: ${{ matrix.os }}
# name: ${{ inputs.test }} (${{ matrix.os }}, ${{ matrix.framework }})
name: (${{ matrix.os }}, ${{ matrix.framework }})
env:
CLOUDSMITH_CICD_USER: ${{ secrets.CLOUDSMITH_CICD_USER }}
Expand Down Expand Up @@ -66,10 +62,3 @@ jobs:
--logger:"GitHubActions;report-warnings=false" --logger:"console;verbosity=normal" \
--framework ${{ matrix.framework }} \
test/Kurrent.Client.Tests
# run: |
# sudo ./gencert.sh
# dotnet test --configuration ${{ matrix.configuration }} --blame \
# --logger:"GitHubActions;report-warnings=false" --logger:"console;verbosity=normal" \
# --framework ${{ matrix.framework }} \
# test/EventStore.Client.${{ inputs.test }}.Tests
5 changes: 1 addition & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ jobs:
strategy:
fail-fast: false
matrix:
# docker-tag: [ ci, lts, previous-lts ]
docker-tag: [ ci ]
# test: [ Streams, PersistentSubscriptions, Operations, UserManagement, ProjectionManagement ]
docker-tag: [ ci, lts, previous-lts ]
name: Test CE (${{ matrix.docker-tag }})
with:
docker-tag: ${{ matrix.docker-tag }}
docker-image: eventstore-ce/eventstoredb-ce
# test: ${{ matrix.test }}
# ee:
# uses: ./.github/workflows/base.yml
# if: ${{ github.repository_owner == 'EventStore' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task InitializeAsync() {
await ContainerSemaphore.WaitAsync();
try {
await Service.Start();
EventStoreVersion = GetEventStoreVersion();
EventStoreVersion = GetKurrentVersion();
EventStoreHasLastStreamPosition = (EventStoreVersion?.Major ?? int.MaxValue) >= 21;
// EventStoreHasLastStreamPosition = true;
} finally {
Expand Down Expand Up @@ -133,7 +133,7 @@ async Task<T> InitClient<T>(Func<T, Task> action, bool execute = true) where T :
return client;
}

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

using var cancellator = new CancellationTokenSource(FromSeconds(30));
Expand All @@ -146,8 +146,7 @@ static Version GetEventStoreVersion() {

using var log = eventstore.Logs(true, cancellator.Token);
foreach (var line in log.ReadToEnd()) {
Logger.Warning("line---> {line}", line);

Logger.Information("EventStoreDB: {Line}", line);
if (line.StartsWith(versionPrefix) &&
Version.TryParse(
new string(ReadVersion(line[(versionPrefix.Length + 1)..]).ToArray()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async Task<int> GetNextAvailablePort(TimeSpan delay = default) {
#if NET
if (socket.Connected) await socket.DisconnectAsync(true);
#else
if (socket.Connected) socket.Disconnect(true);
if (socket.Connected) socket.Disconnect(true);
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task InitializeAsync() {
await ContainerSemaphore.WaitAsync();
try {
await Service.Start();
EventStoreVersion = GetEventStoreVersion();
EventStoreVersion = GetKurrentVersion();
EventStoreHasLastStreamPosition = (EventStoreVersion?.Major ?? int.MaxValue) >= 21;
// EventStoreHasLastStreamPosition = true;
} finally {
Expand Down Expand Up @@ -135,7 +135,7 @@ async Task<T> InitClient<T>(Func<T, Task> action, bool execute = true) where T :
return client;
}

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

using var cancellator = new CancellationTokenSource(FromSeconds(30));
Expand All @@ -148,8 +148,7 @@ static Version GetEventStoreVersion() {

using var log = eventstore.Logs(true, cancellator.Token);
foreach (var line in log.ReadToEnd()) {
Logger.Warning("line---> {line}", line);

Logger.Information("EventStoreDB: {Line}", line);
if (line.StartsWith(versionPrefix) &&
Version.TryParse(
new string(ReadVersion(line[(versionPrefix.Length + 1)..]).ToArray()),
Expand Down
21 changes: 21 additions & 0 deletions test/Kurrent.Client.Tests/Projections/DisableProjectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Kurrent.Client.Tests.TestNode;

namespace Kurrent.Client.Tests.Projections;

public class DisableProjectionTests(ITestOutputHelper output, DisableProjectionTests.CustomFixture fixture)
: KurrentTemporaryTests<DisableProjectionTests.CustomFixture>(output, fixture) {
[Fact]
public async Task disable_projection() {
var name = Names.First();
await Fixture.Projections.DisableAsync(name, userCredentials: TestCredentials.Root);
var result = await Fixture.Projections.GetStatusAsync(name, userCredentials: TestCredentials.Root);
Assert.NotNull(result);
Assert.Contains(["Aborted/Stopped", "Stopped"], x => x == result!.Status);
}

static readonly string[] Names = ["$streams", "$stream_by_category", "$by_category", "$by_event_type", "$by_correlation_id"];

public class CustomFixture : KurrentTemporaryFixture {
public CustomFixture() : base(x => x.RunProjections()) { }
}
}
21 changes: 21 additions & 0 deletions test/Kurrent.Client.Tests/Projections/EnableProjectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Kurrent.Client.Tests.TestNode;

namespace Kurrent.Client.Tests.Projections;

public class EnableProjectionTests(ITestOutputHelper output, EnableProjectionTests.CustomFixture fixture)
: KurrentTemporaryTests<EnableProjectionTests.CustomFixture>(output, fixture) {
[Fact]
public async Task enable_projection() {
var name = Names.First();
await Fixture.Projections.EnableAsync(name, userCredentials: TestCredentials.Root);
var result = await Fixture.Projections.GetStatusAsync(name, userCredentials: TestCredentials.Root);
Assert.NotNull(result);
Assert.Equal("Running", result.Status);
}

static readonly string[] Names = ["$streams", "$stream_by_category", "$by_category", "$by_event_type", "$by_correlation_id"];

public class CustomFixture : KurrentTemporaryFixture {
public CustomFixture() : base(x => x.RunProjections()) { }
}
}
50 changes: 50 additions & 0 deletions test/Kurrent.Client.Tests/Projections/GetProjectionResultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using EventStore.Client;
using Kurrent.Client.Tests.TestNode;

namespace Kurrent.Client.Tests.Projections;

public class GetProjectionResultTests(ITestOutputHelper output, GetProjectionResultTests.CustomFixture fixture)
: KurrentTemporaryTests<GetProjectionResultTests.CustomFixture>(output, fixture) {
[Fact]
public async Task get_result() {
var name = Fixture.GetProjectionName();
Result? result = null;

var projection = $$"""
fromStream('{{name}}').when({
"$init": function() { return { Count: 0 }; },
"$any": function(s, e) { s.Count++; return s; }
});
""";

await Fixture.Projections.CreateContinuousAsync(
name,
projection,
userCredentials: TestCredentials.Root
);

await Fixture.Streams.AppendToStreamAsync(
name,
StreamState.NoStream,
Fixture.CreateTestEvents()
);

await AssertEx.IsOrBecomesTrue(
async () => {
result = await Fixture.Projections.GetResultAsync<Result>(name, userCredentials: TestCredentials.Root);
return result.Count > 0;
}
);

Assert.NotNull(result);
Assert.Equal(1, result!.Count);
}

record Result {
public int Count { get; set; }
}

public class CustomFixture : KurrentTemporaryFixture {
public CustomFixture() : base(x => x.RunProjections()) { }
}
}
51 changes: 51 additions & 0 deletions test/Kurrent.Client.Tests/Projections/GetProjectionStateTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using EventStore.Client;
using Kurrent.Client.Tests.TestNode;

namespace Kurrent.Client.Tests.Projections;

public class GetProjectionStateTests(ITestOutputHelper output, GetProjectionStateTests.CustomFixture fixture)
: KurrentTemporaryTests<GetProjectionStateTests.CustomFixture>(output, fixture) {
[Fact]
public async Task get_state() {
var name = Fixture.GetProjectionName();

var projection = $$"""
fromStream('{{name}}').when({
"$init": function() { return { Count: 0 }; },
"$any": function(s, e) { s.Count++; return s; }
});
""";

Result? result = null;

await Fixture.Projections.CreateContinuousAsync(
name,
projection,
userCredentials: TestCredentials.Root
);

await Fixture.Streams.AppendToStreamAsync(
name,
StreamState.NoStream,
Fixture.CreateTestEvents()
);

await AssertEx.IsOrBecomesTrue(
async () => {
result = await Fixture.Projections.GetStateAsync<Result>(name, userCredentials: TestCredentials.Root);
return result.Count > 0;
}
);

Assert.NotNull(result);
Assert.Equal(1, result!.Count);
}

record Result {
public int Count { get; set; }
}

public class CustomFixture : KurrentTemporaryFixture {
public CustomFixture() : base(x => x.RunProjections()) { }
}
}
21 changes: 21 additions & 0 deletions test/Kurrent.Client.Tests/Projections/GetProjectionStatusTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Kurrent.Client.Tests.TestNode;

namespace Kurrent.Client.Tests.Projections;

public class GetProjectionStatusTests(ITestOutputHelper output, GetProjectionStatusTests.CustomFixture fixture)
: KurrentTemporaryTests<GetProjectionStatusTests.CustomFixture>(output, fixture) {
[Fact]
public async Task get_status() {
var name = Names.First();
var result = await Fixture.Projections.GetStatusAsync(name, userCredentials: TestCredentials.Root);

Assert.NotNull(result);
Assert.Equal(name, result.Name);
}

static readonly string[] Names = ["$streams", "$stream_by_category", "$by_category", "$by_event_type", "$by_correlation_id"];

public class CustomFixture : KurrentTemporaryFixture {
public CustomFixture() : base(x => x.RunProjections()) { }
}
}
Loading

0 comments on commit 7699152

Please sign in to comment.