Skip to content

Commit f7a2c4a

Browse files
committed
Add retry
1 parent fb0bd1f commit f7a2c4a

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/Grpc/Interop/test/InteropTests/InteropTests.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace InteropTests;
99

1010
// All interop test cases, minus GCE authentication specific tests.
1111
// Tests are separate methods so that they can be quarantined separately.
12+
[Retry]
1213
public class InteropTests
1314
{
1415
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(100);
@@ -82,6 +83,39 @@ public InteropTests(ITestOutputHelper output)
8283
public Task ServerCompressedStreaming() => InteropTestCase("server_compressed_streaming");
8384

8485
private async Task InteropTestCase(string name)
86+
{
87+
// Building interop tests processes can be flaky. Sometimes it times out.
88+
// To mitigate this, we retry the test case a few times on timeout.
89+
const int maxRetries = 3;
90+
var attempt = 0;
91+
92+
while (true)
93+
{
94+
attempt++;
95+
96+
try
97+
{
98+
await InteropTestCaseCore(name);
99+
break; // Exit loop on success
100+
}
101+
catch (TimeoutException ex)
102+
{
103+
_output.WriteLine($"Attempt {attempt} failed: {ex.Message}");
104+
105+
if (attempt == maxRetries)
106+
{
107+
_output.WriteLine("Maximum retry attempts reached. Giving up.");
108+
throw;
109+
}
110+
else
111+
{
112+
await Task.Delay(TimeSpan.FromSeconds(1));
113+
}
114+
}
115+
}
116+
}
117+
118+
private async Task InteropTestCaseCore(string name)
85119
{
86120
_output.WriteLine($"Starting {nameof(WebsiteProcess)}.");
87121
using (var serverProcess = new WebsiteProcess(_serverPath, _output))
@@ -91,7 +125,7 @@ private async Task InteropTestCase(string name)
91125
_output.WriteLine($"Waiting for {nameof(WebsiteProcess)} to be ready.");
92126
await serverProcess.WaitForReady().TimeoutAfter(DefaultTimeout);
93127
}
94-
catch (Exception ex)
128+
catch (Exception ex) when (ex is not TimeoutException)
95129
{
96130
var errorMessage = $@"Error while running server process.
97131
@@ -117,7 +151,7 @@ private async Task InteropTestCase(string name)
117151

118152
Assert.Equal(0, clientProcess.ExitCode);
119153
}
120-
catch (Exception ex)
154+
catch (Exception ex) when (ex is not TimeoutException)
121155
{
122156
var errorMessage = $@"Error while running client process.
123157

0 commit comments

Comments
 (0)