Skip to content

Commit fa87e36

Browse files
authored
Don't actually try to connect to network in tests (#144)
## Description of Changes *Describe what has been changed, any new features or bug fixes* ## API - [ ] This is an API breaking change to the SDK *If the API is breaking, please state below what will break* ## Requires SpacetimeDB PRs *List any PRs here that are required for this SDK change to work*
1 parent 9d3336e commit fa87e36

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

sdks/csharp/src/SpacetimeDBClient.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
using SpacetimeDB.Internal;
1212
using SpacetimeDB.ClientApi;
1313
using Thread = System.Threading.Thread;
14-
using System.Runtime.CompilerServices;
15-
16-
[assembly: InternalsVisibleTo("SpacetimeDB.Tests")]
1714

1815
namespace SpacetimeDB
1916
{
@@ -180,6 +177,7 @@ struct PreProcessedMessage
180177
private readonly BlockingCollection<PreProcessedMessage> _preProcessedNetworkMessages =
181178
new(new ConcurrentQueue<PreProcessedMessage>());
182179

180+
internal static bool IsTesting;
183181
internal bool HasPreProcessedMessage => _preProcessedNetworkMessages.Count > 0;
184182

185183
private readonly CancellationTokenSource _preProcessCancellationTokenSource = new();
@@ -582,23 +580,26 @@ internal void Connect(string? token, string uri, string addressOrName)
582580
}
583581

584582
Log.Info($"SpacetimeDBClient: Connecting to {uri} {addressOrName}");
585-
Task.Run(async () =>
583+
if (!IsTesting)
586584
{
587-
try
588-
{
589-
await webSocket.Connect(token, uri, addressOrName, Address);
590-
}
591-
catch (Exception e)
585+
Task.Run(async () =>
592586
{
593-
if (connectionClosed)
587+
try
594588
{
595-
Log.Info("Connection closed gracefully.");
596-
return;
589+
await webSocket.Connect(token, uri, addressOrName, Address);
597590
}
591+
catch (Exception e)
592+
{
593+
if (connectionClosed)
594+
{
595+
Log.Info("Connection closed gracefully.");
596+
return;
597+
}
598598

599-
Log.Exception(e);
600-
}
601-
});
599+
Log.Exception(e);
600+
}
601+
});
602+
}
602603
}
603604

604605
private void OnMessageProcessCompleteUpdate(IEventContext eventContext, List<DbOp> dbOps)

sdks/csharp/tests~/SnapshotTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ public async Task VerifyAllTablesParsed()
268268

269269
Log.Current = new TestLogger(events);
270270

271+
DbConnection.IsTesting = true;
272+
271273
var client =
272274
DbConnection.Builder()
273275
.WithUri("wss://spacetimedb.com")

0 commit comments

Comments
 (0)