Skip to content

Commit 0941979

Browse files
committed
Increase timeouts in tests
1 parent 6aab6bc commit 0941979

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

Assets/Plugins/StreamChat/Tests/StatefulClient/BaseStateIntegrationTests.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected Task<StreamChatClient> GetConnectedOtherClientAsync()
126126
/// <summary>
127127
/// Use this if state update depends on receiving WS event that might come after the REST call was completed
128128
/// </summary>
129-
protected static async Task WaitWhileTrueAsync(Func<bool> condition, int maxIterations = 500)
129+
protected static async Task WaitWhileTrueAsync(Func<bool> condition, int maxIterations = 500, int maxSeconds = 500)
130130
{
131131
var sw = new Stopwatch();
132132
sw.Start();
@@ -138,14 +138,16 @@ protected static async Task WaitWhileTrueAsync(Func<bool> condition, int maxIter
138138
return;
139139
}
140140

141-
if (sw.Elapsed.Seconds > 60)
141+
if (sw.Elapsed.Seconds > maxSeconds)
142142
{
143-
return;
143+
throw new TimeoutException("Timeout while waiting for condition");
144144
}
145145

146146
var delay = (int)Math.Max(1, Math.Min(400, Math.Pow(2, i)));
147147
await Task.Delay(delay);
148148
}
149+
150+
throw new TimeoutException("Timeout while waiting for condition");
149151
}
150152

151153
protected static async Task WaitWhileFalseAsync(Func<bool> condition, int maxIterations = 500, int maxSeconds = 500)
@@ -162,15 +164,17 @@ protected static async Task WaitWhileFalseAsync(Func<bool> condition, int maxIte
162164

163165
if (sw.Elapsed.Seconds > maxSeconds)
164166
{
165-
return;
167+
throw new TimeoutException("Timeout while waiting for condition");
166168
}
167169

168170
var delay = (int)Math.Max(1, Math.Min(400, Math.Pow(2, i)));
169171
await Task.Delay(delay);
170172
}
173+
174+
throw new TimeoutException("Timeout while waiting for condition");
171175
}
172176

173-
protected static async Task WaitWithTimeoutAsync(Task task, int maxSeconds, string exceptionMsg)
177+
protected static async Task WaitWithTimeoutAsync(Task task, string exceptionMsg, int maxSeconds = 300)
174178
{
175179
if (await Task.WhenAny(task, Task.Delay(maxSeconds * 1000)) != task)
176180
{

Assets/Plugins/StreamChat/Tests/StatefulClient/ChannelMembersTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void OnMessageReceived(IStreamChannel channel2, IStreamMessage message)
112112
await WaitWhileTrueAsync(() => channel.Members.All(m => m.User != otherUser));
113113
Assert.NotNull(channel.Members.FirstOrDefault(member => member.User == otherUser));
114114

115-
await WaitWithTimeoutAsync(tcs.Task, 5, $"Event {nameof(channel.MessageReceived)} was not received");
115+
await WaitWithTimeoutAsync(tcs.Task, $"Event {nameof(channel.MessageReceived)} was not received");
116116

117117
channel.MessageReceived -= OnMessageReceived;
118118
}

Assets/Plugins/StreamChat/Tests/StatefulClient/ChannelsTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ void OnChannelUpdated(IStreamChannel channel2)
378378

379379
await channel.UpdateOverwriteAsync(new StreamUpdateOverwriteChannelRequest(channel));
380380

381-
await WaitWithTimeoutAsync(cts.Task, 5, $"Channel {nameof(channel.Updated)} event was not received");
381+
await WaitWithTimeoutAsync(cts.Task, $"Channel {nameof(channel.Updated)} event was not received");
382382

383383
channel.Updated -= OnChannelUpdated;
384384

@@ -431,7 +431,7 @@ void OnChannelUpdated(IStreamChannel channel2)
431431

432432
await channel.UpdateOverwriteAsync(new StreamUpdateOverwriteChannelRequest());
433433

434-
await WaitWithTimeoutAsync(cts.Task, 5, $"Channel {nameof(channel.Updated)} event was not received");
434+
await WaitWithTimeoutAsync(cts.Task, $"Channel {nameof(channel.Updated)} event was not received");
435435

436436
channel.Updated -= OnChannelUpdated;
437437

@@ -489,7 +489,7 @@ await channel.UpdateOverwriteAsync(new StreamUpdateOverwriteChannelRequest
489489
}
490490
});
491491

492-
await WaitWithTimeoutAsync(cts.Task, 5, $"Channel {nameof(channel.Updated)} event was not received");
492+
await WaitWithTimeoutAsync(cts.Task, $"Channel {nameof(channel.Updated)} event was not received");
493493

494494
channel.Updated -= OnChannelUpdated;
495495

@@ -576,8 +576,7 @@ void OnChannelUpdated(IStreamChannel channel2)
576576

577577
await channel.InviteMembersAsync(OtherUserId);
578578

579-
await WaitWithTimeoutAsync(taskCompletionSource.Task, maxSeconds: 3,
580-
$"Event {nameof(channel.Updated)} was not received");
579+
await WaitWithTimeoutAsync(taskCompletionSource.Task, $"Event {nameof(channel.Updated)} was not received");
581580

582581
channel.Updated -= OnChannelUpdated;
583582
}

0 commit comments

Comments
 (0)