Skip to content

Commit 59da678

Browse files
shared regression test utilities
1 parent 07bae76 commit 59da678

9 files changed

Lines changed: 384 additions & 456 deletions

File tree

sdks/csharp/examples~/regression-tests/client/Program.cs

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Runtime.CompilerServices;
1010
using System.Threading;
11+
using RegressionTests.Shared;
1112
using SpacetimeDB;
1213
using SpacetimeDB.Types;
1314

@@ -19,37 +20,6 @@
1920
const string EXPECTED_TEST_EVENT_NAME = "hello";
2021
const ulong EXPECTED_TEST_EVENT_VALUE = 42;
2122

22-
DbConnection ConnectToDB()
23-
{
24-
DbConnection? conn = null;
25-
conn = DbConnection
26-
.Builder()
27-
.WithUri(HOST)
28-
.WithDatabaseName(DBNAME)
29-
.OnConnect(OnConnected)
30-
.OnConnectError(
31-
(err) =>
32-
{
33-
throw err;
34-
}
35-
)
36-
.OnDisconnect(
37-
(conn, err) =>
38-
{
39-
if (err != null)
40-
{
41-
throw err;
42-
}
43-
else
44-
{
45-
throw new Exception("Unexpected disconnect");
46-
}
47-
}
48-
)
49-
.Build();
50-
return conn;
51-
}
52-
5323
uint waiting = 0;
5424
var applied = false;
5525
SubscriptionHandle? handle = null;
@@ -1129,24 +1099,9 @@ ProcedureCallbackResult<Result<ReturnStruct, string>> result
11291099
);
11301100
}
11311101

1132-
System.AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
1133-
{
1134-
Log.Exception($"Unhandled exception: {sender} {args}");
1135-
Environment.Exit(1);
1136-
};
1137-
var db = ConnectToDB();
1138-
Log.Info("Starting timer");
1102+
RegressionTestHarness.RegisterUnhandledExceptionExitHandler();
1103+
var db = RegressionTestHarness.ConnectToDatabase(HOST, DBNAME, OnConnected);
11391104
const int TIMEOUT = 20; // seconds;
1140-
var start = DateTime.Now;
1141-
while (!applied || waiting > 0)
1142-
{
1143-
db.FrameTick();
1144-
Thread.Sleep(100);
1145-
if ((DateTime.Now - start).Seconds > TIMEOUT)
1146-
{
1147-
Log.Error($"Timeout, all events should have elapsed in {TIMEOUT} seconds!");
1148-
Environment.Exit(1);
1149-
}
1150-
}
1105+
RegressionTestHarness.FrameTickUntilComplete(db, () => applied && waiting == 0, TIMEOUT);
11511106
Log.Info("Success");
11521107
Environment.Exit(0);

sdks/csharp/examples~/regression-tests/client/client.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212
<ProjectReference Include="../../../SpacetimeDB.ClientSDK.csproj" />
1313
</ItemGroup>
1414

15+
<ItemGroup>
16+
<Compile Include="../shared/RegressionTestHarness.cs" Link="shared/RegressionTestHarness.cs" />
17+
</ItemGroup>
18+
1519
</Project>

sdks/csharp/examples~/regression-tests/procedure-client/Program.cs

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,13 @@
55

66
using System.Diagnostics;
77
using System.Runtime.CompilerServices;
8+
using RegressionTests.Shared;
89
using SpacetimeDB;
910
using SpacetimeDB.Types;
1011

1112
const string HOST = "http://localhost:3000";
1213
const string DBNAME = "procedure-tests";
1314

14-
DbConnection ConnectToDB()
15-
{
16-
DbConnection? conn = null;
17-
conn = DbConnection.Builder()
18-
.WithUri(HOST)
19-
.WithDatabaseName(DBNAME)
20-
.OnConnect(OnConnected)
21-
.OnConnectError((err) =>
22-
{
23-
throw err;
24-
})
25-
.OnDisconnect((conn, err) =>
26-
{
27-
if (err != null)
28-
{
29-
throw err;
30-
}
31-
else
32-
{
33-
throw new Exception("Unexpected disconnect");
34-
}
35-
})
36-
.Build();
37-
return conn;
38-
}
39-
4015
uint waiting = 0;
4116
bool applied = false;
4217

@@ -201,24 +176,9 @@ void OnSubscriptionApplied(SubscriptionEventContext context)
201176
});
202177
}
203178

204-
System.AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
205-
{
206-
Log.Exception($"Unhandled exception: {sender} {args}");
207-
Environment.Exit(1);
208-
};
209-
var db = ConnectToDB();
210-
Log.Info("Starting timer");
179+
RegressionTestHarness.RegisterUnhandledExceptionExitHandler();
180+
var db = RegressionTestHarness.ConnectToDatabase(HOST, DBNAME, OnConnected);
211181
const int TIMEOUT = 20; // seconds;
212-
var start = DateTime.Now;
213-
while (!applied || waiting > 0)
214-
{
215-
db.FrameTick();
216-
Thread.Sleep(100);
217-
if ((DateTime.Now - start).Seconds > TIMEOUT)
218-
{
219-
Log.Error($"Timeout, all events should have elapsed in {TIMEOUT} seconds!");
220-
Environment.Exit(1);
221-
}
222-
}
182+
RegressionTestHarness.FrameTickUntilComplete(db, () => applied && waiting == 0, TIMEOUT);
223183
Log.Info("Success");
224184
Environment.Exit(0);

sdks/csharp/examples~/regression-tests/procedure-client/client.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@
1414
<ProjectReference Include="../../../SpacetimeDB.ClientSDK.csproj" />
1515
</ItemGroup>
1616

17+
<ItemGroup>
18+
<Compile Include="../shared/RegressionTestHarness.cs" Link="shared/RegressionTestHarness.cs" />
19+
</ItemGroup>
20+
1721
</Project>

sdks/csharp/examples~/regression-tests/republishing/client/Program.cs

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,13 @@
55

66
using System.Diagnostics;
77
using System.Runtime.CompilerServices;
8+
using RegressionTests.Shared;
89
using SpacetimeDB;
910
using SpacetimeDB.Types;
1011

1112
const string HOST = "http://localhost:3000";
1213
const string DBNAME = "republish-test";
1314

14-
DbConnection ConnectToDB()
15-
{
16-
DbConnection? conn = null;
17-
conn = DbConnection.Builder()
18-
.WithUri(HOST)
19-
.WithDatabaseName(DBNAME)
20-
.OnConnect(OnConnected)
21-
.OnConnectError((err) =>
22-
{
23-
throw err;
24-
})
25-
.OnDisconnect((conn, err) =>
26-
{
27-
if (err != null)
28-
{
29-
throw err;
30-
}
31-
else
32-
{
33-
throw new Exception("Unexpected disconnect");
34-
}
35-
})
36-
.Build();
37-
return conn;
38-
}
39-
4015
uint waiting = 0;
4116
bool applied = false;
4217
SubscriptionHandle? handle = null;
@@ -128,24 +103,9 @@ void OnSubscriptionApplied(SubscriptionEventContext context)
128103
Log.Info("Evaluation of ExampleData in republishing test completed.");
129104
}
130105

131-
System.AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
132-
{
133-
Log.Exception($"Unhandled exception: {sender} {args}");
134-
Environment.Exit(1);
135-
};
136-
var db = ConnectToDB();
137-
Log.Info("Starting timer");
106+
RegressionTestHarness.RegisterUnhandledExceptionExitHandler();
107+
var db = RegressionTestHarness.ConnectToDatabase(HOST, DBNAME, OnConnected);
138108
const int TIMEOUT = 20; // seconds;
139-
var start = DateTime.Now;
140-
while (!applied || waiting > 0)
141-
{
142-
db.FrameTick();
143-
Thread.Sleep(100);
144-
if ((DateTime.Now - start).Seconds > TIMEOUT)
145-
{
146-
Log.Error($"Timeout, all events should have elapsed in {TIMEOUT} seconds!");
147-
Environment.Exit(1);
148-
}
149-
}
109+
RegressionTestHarness.FrameTickUntilComplete(db, () => applied && waiting == 0, TIMEOUT);
150110
Log.Info("Success");
151111
Environment.Exit(0);

sdks/csharp/examples~/regression-tests/republishing/client/client.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
<ProjectReference Include="../../../../SpacetimeDB.ClientSDK.csproj" />
1212
</ItemGroup>
1313

14+
<ItemGroup>
15+
<Compile Include="../../shared/RegressionTestHarness.cs" Link="shared/RegressionTestHarness.cs" />
16+
</ItemGroup>
17+
1418
</Project>

0 commit comments

Comments
 (0)