@@ -10,7 +10,12 @@ namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
1010
1111public class SubscriptionResourceTests : IAsyncLifetime
1212{
13- private const int WAIT_PERIOD = 300 ;
13+ #if DEBUG
14+ private const int WAIT_PERIOD = 3000 ; // WSL is slow AF, so for local runs, we're being extra generous
15+ #else
16+ private const int WAIT_PERIOD = 400 ; // For CI runs, a much smaller wait time is acceptable
17+ #endif
18+ private const int TIMEOUT = WAIT_PERIOD + WAIT_PERIOD + 400 ;
1419 private IClient _testUser ;
1520 private Project _testProject ;
1621 private Model _testModel ;
@@ -32,105 +37,101 @@ public async Task InitializeAsync()
3237 _testVersion = await Fixtures . CreateVersion ( _testUser , _testProject . id , _testModel . id ) ;
3338 }
3439
35- [ Fact ]
40+ [ Fact ( Timeout = TIMEOUT ) ]
3641 public async Task UserProjectsUpdated_SubscriptionIsCalled ( )
3742 {
38- UserProjectsUpdatedMessage ? subscriptionMessage = null ;
39-
43+ TaskCompletionSource < UserProjectsUpdatedMessage > tcs = new ( ) ;
4044 using var sub = Sut . CreateUserProjectsUpdatedSubscription ( ) ;
41- sub . Listeners += ( _ , message ) => subscriptionMessage = message ;
45+ sub . Listeners += ( _ , message ) => tcs . SetResult ( message ) ;
4246
4347 await Task . Delay ( WAIT_PERIOD ) ; // Give time to subscription to be setup
4448
4549 var created = await _testUser . Project . Create ( new ( null , null , null ) ) ;
4650
47- await Task . Delay ( WAIT_PERIOD ) ; // Give time for subscription to be triggered
51+ var subscriptionMessage = await tcs . Task ;
4852
4953 subscriptionMessage . Should ( ) . NotBeNull ( ) ;
50- subscriptionMessage ! . id . Should ( ) . Be ( created . id ) ;
54+ subscriptionMessage . id . Should ( ) . Be ( created . id ) ;
5155 subscriptionMessage . type . Should ( ) . Be ( UserProjectsUpdatedMessageType . ADDED ) ;
5256 subscriptionMessage . project . Should ( ) . NotBeNull ( ) ;
5357 }
5458
55- [ Fact ]
59+ [ Fact ( Timeout = TIMEOUT ) ]
5660 public async Task ProjectModelsUpdated_SubscriptionIsCalled ( )
5761 {
58- ProjectModelsUpdatedMessage ? subscriptionMessage = null ;
59-
62+ TaskCompletionSource < ProjectModelsUpdatedMessage > tcs = new ( ) ;
6063 using var sub = Sut . CreateProjectModelsUpdatedSubscription ( _testProject . id ) ;
61- sub . Listeners += ( _ , message ) => subscriptionMessage = message ;
64+ sub . Listeners += ( _ , message ) => tcs . SetResult ( message ) ;
6265
6366 await Task . Delay ( WAIT_PERIOD ) ; // Give time to subscription to be setup
6467
6568 CreateModelInput input = new ( "my model" , "myDescription" , _testProject . id ) ;
6669 var created = await _testUser . Model . Create ( input ) ;
6770
68- await Task . Delay ( WAIT_PERIOD ) ; // Give time for subscription to be triggered
71+ var subscriptionMessage = await tcs . Task ;
6972
7073 subscriptionMessage . Should ( ) . NotBeNull ( ) ;
71- subscriptionMessage ! . id . Should ( ) . Be ( created . id ) ;
74+ subscriptionMessage . id . Should ( ) . Be ( created . id ) ;
7275 subscriptionMessage . type . Should ( ) . Be ( ProjectModelsUpdatedMessageType . CREATED ) ;
7376 subscriptionMessage . model . Should ( ) . NotBeNull ( ) ;
7477 }
7578
76- [ Fact ]
79+ [ Fact ( Timeout = TIMEOUT ) ]
7780 public async Task ProjectUpdated_SubscriptionIsCalled ( )
7881 {
79- ProjectUpdatedMessage ? subscriptionMessage = null ;
80-
82+ TaskCompletionSource < ProjectUpdatedMessage > tcs = new ( ) ;
8183 using var sub = Sut . CreateProjectUpdatedSubscription ( _testProject . id ) ;
82- sub . Listeners += ( _ , message ) => subscriptionMessage = message ;
84+ sub . Listeners += ( _ , message ) => tcs . SetResult ( message ) ;
8385
8486 await Task . Delay ( WAIT_PERIOD ) ; // Give time to subscription to be setup
8587
8688 var input = new ProjectUpdateInput ( _testProject . id , "This is my new name" ) ;
8789 var created = await _testUser . Project . Update ( input ) ;
8890
89- await Task . Delay ( WAIT_PERIOD ) ; // Give time for subscription to be triggered
91+ var subscriptionMessage = await tcs . Task ;
9092
9193 subscriptionMessage . Should ( ) . NotBeNull ( ) ;
92- subscriptionMessage ! . id . Should ( ) . Be ( created . id ) ;
94+ subscriptionMessage . id . Should ( ) . Be ( created . id ) ;
9395 subscriptionMessage . type . Should ( ) . Be ( ProjectUpdatedMessageType . UPDATED ) ;
9496 subscriptionMessage . project . Should ( ) . NotBeNull ( ) ;
9597 }
9698
97- [ Fact ]
99+ [ Fact ( Timeout = TIMEOUT ) ]
98100 public async Task ProjectVersionsUpdated_SubscriptionIsCalled ( )
99101 {
100- ProjectVersionsUpdatedMessage ? subscriptionMessage = null ;
101-
102+ TaskCompletionSource < ProjectVersionsUpdatedMessage > tcs = new ( ) ;
102103 using var sub = Sut . CreateProjectVersionsUpdatedSubscription ( _testProject . id ) ;
103- sub . Listeners += ( _ , message ) => subscriptionMessage = message ;
104+ sub . Listeners += ( _ , message ) => tcs . SetResult ( message ) ;
104105
105106 await Task . Delay ( WAIT_PERIOD ) ; // Give time to subscription to be setup
106107
107108 var created = await Fixtures . CreateVersion ( _testUser , _testProject . id , _testModel . id ) ;
108109
109- await Task . Delay ( WAIT_PERIOD ) ; // Give time for subscription to be triggered
110+ var subscriptionMessage = await tcs . Task ;
110111
111112 subscriptionMessage . Should ( ) . NotBeNull ( ) ;
112- subscriptionMessage ! . id . Should ( ) . Be ( created . id ) ;
113+ subscriptionMessage . id . Should ( ) . Be ( created . id ) ;
113114 subscriptionMessage . type . Should ( ) . Be ( ProjectVersionsUpdatedMessageType . CREATED ) ;
114115 subscriptionMessage . version . Should ( ) . NotBeNull ( ) ;
115116 }
116117
117- [ Fact ( Skip = CommentResourceTests . SERVER_SKIP_MESSAGE ) ]
118+ [ Fact ( Skip = CommentResourceTests . SERVER_SKIP_MESSAGE , Timeout = TIMEOUT ) ]
118119 public async Task ProjectCommentsUpdated_SubscriptionIsCalled ( )
119120 {
120121 string resourceIdString = $ "{ _testProject . id } ,{ _testModel . id } ,{ _testVersion } ";
121- ProjectCommentsUpdatedMessage ? subscriptionMessage = null ;
122122
123+ TaskCompletionSource < ProjectCommentsUpdatedMessage > tcs = new ( ) ;
123124 using var sub = Sut . CreateProjectCommentsUpdatedSubscription ( new ( _testProject . id , resourceIdString ) ) ;
124- sub . Listeners += ( _ , message ) => subscriptionMessage = message ;
125+ sub . Listeners += ( _ , message ) => tcs . SetResult ( message ) ;
125126
126127 await Task . Delay ( WAIT_PERIOD ) ; // Give time to subscription to be setup
127128
128129 var created = await Fixtures . CreateComment ( _testUser , _testProject . id , _testModel . id , _testVersion . id ) ;
129130
130- await Task . Delay ( WAIT_PERIOD ) ; // Give time for subscription to be triggered
131+ var subscriptionMessage = await tcs . Task ;
131132
132133 subscriptionMessage . Should ( ) . NotBeNull ( ) ;
133- subscriptionMessage ! . id . Should ( ) . Be ( created . id ) ;
134+ subscriptionMessage . id . Should ( ) . Be ( created . id ) ;
134135 subscriptionMessage . type . Should ( ) . Be ( ProjectCommentsUpdatedMessageType . CREATED ) ;
135136 subscriptionMessage . comment . Should ( ) . NotBeNull ( ) ;
136137 }
0 commit comments