Skip to content

Commit ddfc751

Browse files
authored
tests: add json tests submodule, fix test runner (#25)
1 parent d634df9 commit ddfc751

File tree

5 files changed

+68
-1642
lines changed

5 files changed

+68
-1642
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
[submodule "src/questdb-client-test"]
23
path = src/questdb-client-test
34
url = https://github.com/questdb/questdb-client-test.git

src/net-questdb-client-tests/JsonSpecTestRunner.cs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,15 @@ public async Task RunTcp(TestCase testCase)
100100

101101
if (testCase.result.status == "SUCCESS")
102102
{
103-
WaitAssert(srv, testCase.result.line + "\n");
103+
if (testCase.result.anyLines == null || testCase.result.anyLines.Length == 0)
104+
{
105+
WaitAssert(srv, testCase.result.line + "\n");
106+
}
107+
else
108+
{
109+
WaitAssert(srv, testCase.result.anyLines);
110+
}
111+
104112
}
105113
else if (testCase.result.status == "ERROR")
106114
{
@@ -180,14 +188,19 @@ public async Task RunHttp(TestCase testCase)
180188

181189
if (testCase.result.status == "SUCCESS")
182190
{
183-
Assert.That(
184-
server.GetReceiveBuffer().ToString(),
185-
Is.EqualTo(testCase.result.line + "\n")
186-
);
191+
var textReceived = server.GetReceiveBuffer().ToString();
192+
if (testCase.result.anyLines == null || testCase.result.anyLines.Length == 0)
193+
{
194+
Assert.That(textReceived, Is.EqualTo(testCase.result.line + "\n"));
195+
}
196+
else
197+
{
198+
AssertMany(testCase.result.anyLines, textReceived);
199+
}
187200
}
188201
else if (testCase.result.status == "ERROR")
189202
{
190-
Assert.NotNull(exception, $"Exception should be thrown: {exception}");
203+
Assert.NotNull(exception, "Exception should be thrown");
191204
if (exception is NotSupportedException)
192205
{
193206
throw exception;
@@ -197,8 +210,27 @@ public async Task RunHttp(TestCase testCase)
197210
{
198211
Assert.Fail("Unsupported test case result status: " + testCase.result.status);
199212
}
213+
}
200214

201-
await server.StopAsync();
215+
private void WaitAssert(DummyIlpServer srv, string[] resultAnyLines)
216+
{
217+
var minExpectedLen = resultAnyLines.Select(l => Encoding.UTF8.GetBytes(l).Length).Min();
218+
for (var i = 0; i < 500 && srv.TotalReceived < minExpectedLen; i++)
219+
{
220+
Thread.Sleep(10);
221+
}
222+
223+
var textReceived = srv.GetTextReceived();
224+
AssertMany(resultAnyLines, textReceived);
225+
}
226+
227+
private static void AssertMany(string[] resultAnyLines, string textReceived)
228+
{
229+
bool anyMatch = resultAnyLines.Any(l => l.Equals(textReceived) || (l + "\n").Equals(textReceived));
230+
if (!anyMatch)
231+
{
232+
Assert.Fail(textReceived + ": did not match any expected results");
233+
}
202234
}
203235

204236
private static void WaitAssert(DummyIlpServer srv, string expected)
@@ -254,5 +286,6 @@ public class TestCaseResult
254286
{
255287
public string status { get; set; }
256288
public string line { get; set; }
289+
public string[]? anyLines { get; set; }
257290
}
258291
}

src/questdb-client-test

Submodule questdb-client-test added at 0a9c092

0 commit comments

Comments
 (0)