From 12df19e431ea35c25278c0faa38ff19d2ad5e913 Mon Sep 17 00:00:00 2001 From: Jedd Morgan <45512892+JR-Morgan@users.noreply.github.com> Date: Tue, 10 Feb 2026 09:52:19 +0000 Subject: [PATCH] fix(test): Ensure `InitializeWebsocket` runs async (#437) * Force InitializeWebsocket * experiment with lower values * let's play it safe --- src/Speckle.Sdk/Api/GraphQL/Client.cs | 20 +++++++++++++++++++ .../Resources/SubscriptionResourceTests.cs | 7 ++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Speckle.Sdk/Api/GraphQL/Client.cs b/src/Speckle.Sdk/Api/GraphQL/Client.cs index abe96585..e53064be 100644 --- a/src/Speckle.Sdk/Api/GraphQL/Client.cs +++ b/src/Speckle.Sdk/Api/GraphQL/Client.cs @@ -87,6 +87,26 @@ public sealed class Client : ISpeckleGraphQLClient, IClient catch (Exception ex) when (!ex.IsFatal()) { } } + /// + /// Ensure the 's websocket is fully initialized. + ///
+ /// You don't need to call this function, if you don't, then it will be setup for you when you call (e.g. when you create a ), + /// but due to 's WebSocket implementation, it's not awaited (deferred) thus the subscription make take a while to actually be setup. + ///
+ /// + /// 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. + /// + public async Task InitializeWebsocket() + { + if (GQLClient.WebSocketSubProtocol is null) + { + await GQLClient.InitializeWebsocketConnection().ConfigureAwait(false); + } + } + internal async Task ExecuteWithResiliencePolicies(Func> func) => await GraphQLRetry .ExecuteAsync( diff --git a/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/SubscriptionResourceTests.cs b/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/SubscriptionResourceTests.cs index e680e8b8..3ef89104 100644 --- a/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/SubscriptionResourceTests.cs +++ b/tests/Speckle.Sdk.Tests.Integration/Api/GraphQL/Resources/SubscriptionResourceTests.cs @@ -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);