Skip to content

Commit 79aff47

Browse files
authored
Feature/refactor delete channel test to async (#133)
* Fix state update after `channel.truncated` event with a past date * Add waiting for new message.received event when truncating in a unit test + add max waiting of 60s for a condition * Add IStreamChannel.FreezeAsync & IStreamChannel.UnfreezeAsync + add unit tests * Refactor When_deleting_existing_channel_expect_success to async/await and wrap in ConnectAndExecute in order to handle rate exceeded error with additional delay
1 parent 673a470 commit 79aff47

2 files changed

Lines changed: 14 additions & 19 deletions

File tree

Assets/Plugins/StreamChat/Tests/LowLevelClient/Integration/BaseIntegrationTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public async void OneTimeTearDown()
4545
/// Id of other user than currently logged one
4646
/// </summary>
4747
protected static string OtherUserId => StreamTestClients.Instance.OtherUserId;
48-
48+
4949
protected static OwnUser LowLevelClientOwnUser => StreamTestClients.Instance.LowLevelClientOwnUser;
5050

5151
protected static IEnumerator ReconnectClient() => StreamTestClients.Instance.ReconnectLowLevelClientClient();
@@ -115,16 +115,15 @@ protected static async Task<T> Try<T>(Func<Task<T>> task, Predicate<T> successCo
115115
while (attempt <= maxAttempts)
116116
{
117117
attempt++;
118-
118+
119119
response = await task();
120120

121121
if (successCondition(response))
122122
{
123123
return response;
124124
}
125125

126-
var power = Math.Max(attempt, 5);
127-
var delay = initTimeoutMs * Math.Pow(2, power);
126+
var delay = Math.Min(1000, initTimeoutMs + Math.Pow(2, attempt));
128127
await Task.Delay((int)delay);
129128
}
130129

@@ -253,7 +252,7 @@ await LowLevelClient.ChannelApi.DeleteChannelsAsync(new DeleteChannelsRequest
253252

254253
_tempChannelsCidsToDelete.Clear();
255254
}
256-
255+
257256
private static async Task ExecuteAsync(Func<Task> test)
258257
{
259258
const int maxAttempts = 7;
@@ -285,7 +284,8 @@ private static async Task ExecuteAsync(Func<Task> test)
285284

286285
if (!completed)
287286
{
288-
throw new AggregateException($"Failed all attempts. Last Exception: {exceptions.Last().Message} ", exceptions);
287+
throw new AggregateException($"Failed all attempts. Last Exception: {exceptions.Last().Message} ",
288+
exceptions);
289289
}
290290
}
291291
}

Assets/Plugins/StreamChat/Tests/LowLevelClient/Integration/ChannelApiIntegrationTests.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,23 +312,18 @@ private async Task When_start_watching_a_channel_expect_user_included_in_watcher
312312
}
313313

314314
[UnityTest]
315-
public IEnumerator When_deleting_existing_channel_expect_success()
316-
{
317-
yield return LowLevelClient.WaitForClientToConnect();
315+
public IEnumerator When_deleting_existing_channel_expect_success()
316+
=> ConnectAndExecute(When_deleting_existing_channel_expect_success_Async);
318317

319-
var channelType = "messaging";
318+
private async Task When_deleting_existing_channel_expect_success_Async()
319+
{
320+
const string channelType = "messaging";
320321

321-
ChannelState channelState = null;
322-
yield return CreateTempUniqueChannel(channelType, new ChannelGetOrCreateRequest(),
323-
state => channelState = state);
322+
var channelState = await CreateTempUniqueChannelAsync(channelType, new ChannelGetOrCreateRequest());
324323
var channelId = channelState.Channel.Id;
325324

326-
var deleteChannelTask
327-
= LowLevelClient.ChannelApi.DeleteChannelAsync(channelType, channelId, isHardDelete: false);
328-
yield return deleteChannelTask.RunAsIEnumerator(response =>
329-
{
330-
Assert.AreEqual(response.Channel.Id, channelId);
331-
});
325+
var response = await LowLevelClient.ChannelApi.DeleteChannelAsync(channelType, channelId, isHardDelete: false);
326+
Assert.AreEqual(response.Channel.Id, channelId);
332327
}
333328

334329
[UnityTest]

0 commit comments

Comments
 (0)