Skip to content

Commit c555677

Browse files
committed
* Add retries to GetQueueAsync
1 parent 4f16bca commit c555677

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

Tests/HttpApiClient.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,37 @@ public async Task<int> KillConnectionAsync(string containerId)
115115
return killed;
116116
}
117117

118-
public Task<Queue> GetQueueAsync(string queueNameStr)
118+
public async Task<Queue> GetQueueAsync(string queueNameStr)
119119
{
120-
var queueName = new QueueName(queueNameStr, "/");
121-
return _managementClient.GetQueueAsync(queueName);
120+
ushort retries = 20;
121+
do
122+
{
123+
try
124+
{
125+
var queueName = new QueueName(queueNameStr, "/");
126+
return await _managementClient.GetQueueAsync(queueName);
127+
}
128+
catch (UnexpectedHttpStatusCodeException ex)
129+
{
130+
if (ex.StatusCode == HttpStatusCode.NotFound)
131+
{
132+
retries--;
133+
if (retries == 0)
134+
{
135+
throw;
136+
}
137+
}
138+
else
139+
{
140+
throw;
141+
}
142+
}
143+
144+
await Task.Delay(500);
145+
146+
} while (retries >= 0);
147+
148+
throw new InvalidOperationException($"could not retrieve queue '{queueNameStr}' within 10 seconds!");
122149
}
123150

124151
public async Task<bool> CheckExchangeAsync(string exchangeNameStr, bool checkExisting = true)

0 commit comments

Comments
 (0)