@@ -59,9 +59,33 @@ protected async Task<IStreamChannel> CreateUniqueTempChannelAsync(string name =
5959 var channelId = "random-channel-11111-" + Guid . NewGuid ( ) ;
6060 var client = overrideClient ?? Client ;
6161
62- var channelState = await client . InternalGetOrCreateChannelWithIdAsync ( ChannelType . Messaging , channelId , name , watch : watch ) ;
63- _tempChannels . Add ( channelState ) ;
64- return channelState ;
62+ const int maxAttempts = 20 ;
63+ for ( var i = 0 ; i < maxAttempts ; i ++ )
64+ {
65+ try
66+ {
67+ var channelState = await client . InternalGetOrCreateChannelWithIdAsync ( ChannelType . Messaging , channelId , name , watch : watch ) ;
68+ _tempChannels . Add ( channelState ) ;
69+ return channelState ;
70+ }
71+ catch ( StreamApiException e )
72+ {
73+ if ( i == maxAttempts - 1 )
74+ {
75+ throw ;
76+ }
77+
78+ if ( e . IsRateLimitExceededError ( ) )
79+ {
80+ await Task . Delay ( i * 5 * 1000 ) ;
81+ continue ;
82+ }
83+
84+ throw ;
85+ }
86+ }
87+
88+ throw new InvalidOperationException ( $ "{ nameof ( CreateUniqueTempChannelAsync ) } failed to due to max attempts reached.") ;
6589 }
6690
6791 /// <summary>
@@ -124,7 +148,7 @@ protected static async Task WaitWhileTrueAsync(Func<bool> condition, int maxIter
124148 }
125149 }
126150
127- protected static async Task WaitWhileFalseAsync ( Func < bool > condition , int maxIterations = 500 )
151+ protected static async Task WaitWhileFalseAsync ( Func < bool > condition , int maxIterations = 500 , int maxSeconds = 500 )
128152 {
129153 var sw = new Stopwatch ( ) ;
130154 sw . Start ( ) ;
@@ -136,7 +160,7 @@ protected static async Task WaitWhileFalseAsync(Func<bool> condition, int maxIte
136160 return ;
137161 }
138162
139- if ( sw . Elapsed . Seconds > 60 )
163+ if ( sw . Elapsed . Seconds > maxSeconds )
140164 {
141165 return ;
142166 }
0 commit comments