fix(test): Ensure InitializeWebsocket runs async (#437)

* Force InitializeWebsocket

* experiment with lower values

* let's play it safe
This commit is contained in:
Jedd Morgan
2026-02-10 09:52:19 +00:00
committed by GitHub
parent c186d98ea7
commit 12df19e431
2 changed files with 24 additions and 3 deletions
+20
View File
@@ -87,6 +87,26 @@ public sealed class Client : ISpeckleGraphQLClient, IClient
catch (Exception ex) when (!ex.IsFatal()) { }
}
/// <summary>
/// Ensure the <see cref="GQLClient"/>'s websocket is fully initialized.
/// <br/>
/// You don't <i>need</i> to call this function, if you don't, then it will be setup for you when you call <see cref="SubscribeTo"/> (e.g. when you create a <see cref="Subscription"/>),
/// but due to <see cref="GraphQL"/>'s WebSocket implementation, it's not awaited (deferred) thus the subscription make take a while to actually be setup.
/// </summary>
/// <remarks>
/// We only use websockets for GraphQL subscriptions, so if you're not using subscriptions, don't call this
///
/// Note. due to other sources (potentially on the GraphQL side) you still need a ~100ms delay between setting up the subscription, and being able to relaibly trigger it
/// This should only really negatively affect test projects.
/// </remarks>
public async Task InitializeWebsocket()
{
if (GQLClient.WebSocketSubProtocol is null)
{
await GQLClient.InitializeWebsocketConnection().ConfigureAwait(false);
}
}
internal async Task<T> ExecuteWithResiliencePolicies<T>(Func<Task<T>> func) =>
await GraphQLRetry
.ExecuteAsync<T, SpeckleGraphQLInternalErrorException>(
@@ -11,11 +11,11 @@ namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
public class SubscriptionResourceTests : IAsyncLifetime
{
#if DEBUG
private const int WAIT_PERIOD = 4000; // WSL is slow AF, so for local runs, we're being extra generous
private const int WAIT_PERIOD = 3000; // WSL is slow AF, so for local runs, we're being extra generous
#else
private const int WAIT_PERIOD = 500; // For CI runs, a much smaller wait time is acceptable
private const int WAIT_PERIOD = 400; // For CI runs, a much smaller wait time is acceptable
#endif
private const int TIMEOUT = WAIT_PERIOD + WAIT_PERIOD + 500;
private const int TIMEOUT = WAIT_PERIOD + 1000;
private IClient _testUser;
private Project _testProject;
private Model _testModel;
@@ -32,6 +32,7 @@ public class SubscriptionResourceTests : IAsyncLifetime
public async Task InitializeAsync()
{
_testUser = await Fixtures.SeedUserWithClient();
await _testUser.InitializeWebsocket();
_testProject = await _testUser.Project.Create(new("test project123", "desc", null));
_testModel = await _testUser.Model.Create(new("test model", "desc", _testProject.id));
_testVersion = await Fixtures.CreateVersion(_testUser, _testProject.id, _testModel.id);