Skip to content

Commit f68cec0

Browse files
committedJan 7, 2025
Testing something
1 parent 740872b commit f68cec0

File tree

2 files changed

+72
-68
lines changed

2 files changed

+72
-68
lines changed
 

‎test/Kurrent.Client.Tests.Common/Fixtures/KurrentPermanentFixture.cs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected KurrentPermanentFixture(ConfigureFixture configure) {
4141
public KurrentFixtureOptions Options { get; }
4242
public Faker Faker { get; } = new Faker();
4343

44-
// public Version EventStoreVersion { get; private set; } = null!;
44+
public Version EventStoreVersion { get; private set; } = null!;
4545
public bool EventStoreHasLastStreamPosition { get; private set; }
4646

4747
public KurrentClient Streams { get; private set; } = null!;
@@ -87,9 +87,9 @@ public async Task InitializeAsync() {
8787
await ContainerSemaphore.WaitAsync();
8888
try {
8989
await Service.Start();
90-
// EventStoreVersion = GetEventStoreVersion();
91-
// EventStoreHasLastStreamPosition = (EventStoreVersion?.Major ?? int.MaxValue) >= 21;
92-
EventStoreHasLastStreamPosition = true;
90+
EventStoreVersion = GetEventStoreVersion();
91+
EventStoreHasLastStreamPosition = (EventStoreVersion?.Major ?? int.MaxValue) >= 21;
92+
// EventStoreHasLastStreamPosition = true;
9393
} finally {
9494
ContainerSemaphore.Release();
9595
}
@@ -133,36 +133,38 @@ async Task<T> InitClient<T>(Func<T, Task> action, bool execute = true) where T :
133133
return client;
134134
}
135135

136-
// static Version GetEventStoreVersion() {
137-
// const string versionPrefix = "EventStoreDB version";
138-
//
139-
// using var cancellator = new CancellationTokenSource(FromSeconds(30));
140-
// using var eventstore = new Builder()
141-
// .UseContainer()
142-
// .UseImage(GlobalEnvironment.DockerImage)
143-
// .Command("--version")
144-
// .Build()
145-
// .Start();
146-
//
147-
// using var log = eventstore.Logs(true, cancellator.Token);
148-
// foreach (var line in log.ReadToEnd()) {
149-
// if (line.StartsWith(versionPrefix) &&
150-
// Version.TryParse(
151-
// new string(ReadVersion(line[(versionPrefix.Length + 1)..]).ToArray()),
152-
// out var version
153-
// )) {
154-
// return version;
155-
// }
156-
// }
157-
//
158-
// throw new InvalidOperationException("Could not determine server version.");
159-
//
160-
// IEnumerable<char> ReadVersion(string s) {
161-
// foreach (var c in s.TakeWhile(c => c == '.' || char.IsDigit(c))) {
162-
// yield return c;
163-
// }
164-
// }
165-
// }
136+
static Version GetEventStoreVersion() {
137+
const string versionPrefix = "EventStoreDB version";
138+
139+
using var cancellator = new CancellationTokenSource(FromSeconds(30));
140+
using var eventstore = new Builder()
141+
.UseContainer()
142+
.UseImage(GlobalEnvironment.DockerImage)
143+
.Command("--version")
144+
.Build()
145+
.Start();
146+
147+
using var log = eventstore.Logs(true, cancellator.Token);
148+
foreach (var line in log.ReadToEnd()) {
149+
Logger.Warning("line---> {line}", line);
150+
151+
if (line.StartsWith(versionPrefix) &&
152+
Version.TryParse(
153+
new string(ReadVersion(line[(versionPrefix.Length + 1)..]).ToArray()),
154+
out var version
155+
)) {
156+
return version;
157+
}
158+
}
159+
160+
throw new InvalidOperationException("Could not determine server version.");
161+
162+
IEnumerable<char> ReadVersion(string s) {
163+
foreach (var c in s.TakeWhile(c => c == '.' || char.IsDigit(c))) {
164+
yield return c;
165+
}
166+
}
167+
}
166168
}
167169

168170
public async Task DisposeAsync() {

‎test/Kurrent.Client.Tests.Common/Fixtures/KurrentTemporaryFixture.cs

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected KurrentTemporaryFixture(ConfigureFixture configure) {
4444
public KurrentFixtureOptions Options { get; }
4545
public Faker Faker { get; } = new Faker();
4646

47-
// public Version EventStoreVersion { get; private set; } = null!;
47+
public Version EventStoreVersion { get; private set; } = null!;
4848
public bool EventStoreHasLastStreamPosition { get; private set; }
4949

5050
public KurrentClient Streams { get; private set; } = null!;
@@ -89,9 +89,9 @@ public async Task InitializeAsync() {
8989
await ContainerSemaphore.WaitAsync();
9090
try {
9191
await Service.Start();
92-
// EventStoreVersion = GetEventStoreVersion();
93-
// EventStoreHasLastStreamPosition = (EventStoreVersion?.Major ?? int.MaxValue) >= 21;
94-
EventStoreHasLastStreamPosition = true;
92+
EventStoreVersion = GetEventStoreVersion();
93+
EventStoreHasLastStreamPosition = (EventStoreVersion?.Major ?? int.MaxValue) >= 21;
94+
// EventStoreHasLastStreamPosition = true;
9595
} finally {
9696
ContainerSemaphore.Release();
9797
}
@@ -135,36 +135,38 @@ async Task<T> InitClient<T>(Func<T, Task> action, bool execute = true) where T :
135135
return client;
136136
}
137137

138-
// static Version GetEventStoreVersion() {
139-
// const string versionPrefix = "EventStoreDB version";
140-
//
141-
// using var cancellator = new CancellationTokenSource(FromSeconds(30));
142-
// using var eventstore = new Builder()
143-
// .UseContainer()
144-
// .UseImage(GlobalEnvironment.DockerImage)
145-
// .Command("--version")
146-
// .Build()
147-
// .Start();
148-
//
149-
// using var log = eventstore.Logs(true, cancellator.Token);
150-
// foreach (var line in log.ReadToEnd()) {
151-
// if (line.StartsWith(versionPrefix) &&
152-
// Version.TryParse(
153-
// new string(ReadVersion(line[(versionPrefix.Length + 1)..]).ToArray()),
154-
// out var version
155-
// )) {
156-
// return version;
157-
// }
158-
// }
159-
//
160-
// throw new InvalidOperationException("Could not determine server version.");
161-
//
162-
// IEnumerable<char> ReadVersion(string s) {
163-
// foreach (var c in s.TakeWhile(c => c == '.' || char.IsDigit(c))) {
164-
// yield return c;
165-
// }
166-
// }
167-
// }
138+
static Version GetEventStoreVersion() {
139+
const string versionPrefix = "EventStoreDB version";
140+
141+
using var cancellator = new CancellationTokenSource(FromSeconds(30));
142+
using var eventstore = new Builder()
143+
.UseContainer()
144+
.UseImage(GlobalEnvironment.DockerImage)
145+
.Command("--version")
146+
.Build()
147+
.Start();
148+
149+
using var log = eventstore.Logs(true, cancellator.Token);
150+
foreach (var line in log.ReadToEnd()) {
151+
Logger.Warning("line---> {line}", line);
152+
153+
if (line.StartsWith(versionPrefix) &&
154+
Version.TryParse(
155+
new string(ReadVersion(line[(versionPrefix.Length + 1)..]).ToArray()),
156+
out var version
157+
)) {
158+
return version;
159+
}
160+
}
161+
162+
throw new InvalidOperationException("Could not determine server version.");
163+
164+
IEnumerable<char> ReadVersion(string s) {
165+
foreach (var c in s.TakeWhile(c => c == '.' || char.IsDigit(c))) {
166+
yield return c;
167+
}
168+
}
169+
}
168170
}
169171

170172
public async Task DisposeAsync() {

0 commit comments

Comments
 (0)
Failed to load comments.