Skip to content

Commit

Permalink
Don't actually try to connect to network in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Oct 2, 2024
1 parent 00d2741 commit 7062f68
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/SpacetimeDBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
using SpacetimeDB.Internal;
using SpacetimeDB.ClientApi;
using Thread = System.Threading.Thread;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("SpacetimeDB.Tests")]

namespace SpacetimeDB
{
Expand Down Expand Up @@ -180,6 +177,7 @@ struct PreProcessedMessage
private readonly BlockingCollection<PreProcessedMessage> _preProcessedNetworkMessages =
new(new ConcurrentQueue<PreProcessedMessage>());

internal static bool IsTesting;
internal bool HasPreProcessedMessage => _preProcessedNetworkMessages.Count > 0;

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

Log.Info($"SpacetimeDBClient: Connecting to {uri} {addressOrName}");
Task.Run(async () =>
if (!IsTesting)
{
try
{
await webSocket.Connect(token, uri, addressOrName, Address);
}
catch (Exception e)
Task.Run(async () =>
{
if (connectionClosed)
try
{
Log.Info("Connection closed gracefully.");
return;
await webSocket.Connect(token, uri, addressOrName, Address);
}
catch (Exception e)
{
if (connectionClosed)
{
Log.Info("Connection closed gracefully.");
return;
}

Log.Exception(e);
}
});
Log.Exception(e);
}
});
}
}

private void OnMessageProcessCompleteUpdate(IEventContext eventContext, List<DbOp> dbOps)
Expand Down
2 changes: 2 additions & 0 deletions tests~/SnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ public async Task VerifyAllTablesParsed()

Log.Current = new TestLogger(events);

DbConnection.IsTesting = true;

var client =
DbConnection.Builder()
.WithUri("wss://spacetimedb.com")
Expand Down

0 comments on commit 7062f68

Please sign in to comment.