@@ -49,11 +49,14 @@ protected static IEnumerable<AuthCredentials> OtherAdminUsersCredentials
4949 /// <summary>
5050 /// Create temp channel with random id that will be removed in [TearDown]
5151 /// </summary>
52- protected async Task < IStreamChannel > CreateUniqueTempChannelAsync ( string name = null , bool watch = true )
52+ protected async Task < IStreamChannel > CreateUniqueTempChannelAsync ( string name = null , bool watch = true , StreamChatClient overrideClient = null )
5353 {
5454 var channelId = "random-channel-11111-" + Guid . NewGuid ( ) ;
55+ var client = overrideClient ?? Client ;
5556
56- var channelState = await Client . InternalGetOrCreateChannelWithIdAsync ( ChannelType . Messaging , channelId , name , watch : watch ) ;
57+ var channelState = await TryAsync ( ( ) => client . InternalGetOrCreateChannelWithIdAsync ( ChannelType . Messaging , channelId , name , watch : watch ) ,
58+ result => result != null ,
59+ ex => ex is StreamApiException apiException && apiException . IsRateLimitExceededError ( ) ) ;
5760 _tempChannels . Add ( channelState ) ;
5861 return channelState ;
5962 }
@@ -151,19 +154,28 @@ protected static async Task WaitWithTimeoutAsync(Task task, int maxSeconds, stri
151154 /// <summary>
152155 /// Timeout will be doubled on each subsequent attempt. So max timeout = <see cref="initTimeoutMs"/> * 2^<see cref="maxAttempts"/>
153156 /// </summary>
154- protected static async Task < T > TryAsync < T > ( Func < Task < T > > task , Predicate < T > successCondition , int maxAttempts = 20 ,
157+ protected static async Task < T > TryAsync < T > ( Func < Task < T > > task , Predicate < T > successCondition , Func < Exception , bool > continueOnException = null , int maxAttempts = 20 ,
155158 int initTimeoutMs = 150 )
156159 {
157160 var response = default ( T ) ;
158161
159162 var attemptsLeft = maxAttempts ;
160163 while ( attemptsLeft > 0 )
161164 {
162- response = await task ( ) ;
163-
164- if ( successCondition ( response ) )
165+ try
166+ {
167+ response = await task ( ) ;
168+ if ( successCondition ( response ) )
169+ {
170+ return response ;
171+ }
172+ }
173+ catch ( Exception ex )
165174 {
166- return response ;
175+ if ( continueOnException == null || ! continueOnException ( ex ) )
176+ {
177+ throw ex ;
178+ }
167179 }
168180
169181 var delay = initTimeoutMs * Math . Pow ( 2 , ( maxAttempts - attemptsLeft ) ) ;
@@ -243,4 +255,4 @@ private async Task DeleteTempChannelsAsync()
243255 }
244256 }
245257}
246- #endif
258+ #endif
0 commit comments