Skip to content

Commit 5c403b5

Browse files
committed
Address review comments.
1 parent a506170 commit 5c403b5

1 file changed

Lines changed: 39 additions & 12 deletions

File tree

‎gae-interop-testing/gae-jdk8/build.gradle‎

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,54 @@ tasks.register("runInteropTestRemote") {
132132
def result2 = null
133133
String result1Body = ""
134134
String result2Body = ""
135+
boolean success = false
136+
int lastResult1Code = -1
137+
int lastResult2Code = -1
135138
for (int attempt = 0; attempt < maxChannelReuseRetries; attempt++) {
136139
try {
137140
result1 = client.newCall(request).execute()
138141
result2 = client.newCall(request).execute()
139-
if (result1.code() == 200 && result2.code() == 200) {
142+
if (result1 != null) {
143+
lastResult1Code = result1.code()
144+
}
145+
if (result2 != null) {
146+
lastResult2Code = result2.code()
147+
}
148+
if (lastResult1Code == 200 && lastResult2Code == 200) {
149+
success = true
140150
break
141151
}
142-
logger.log(LogLevel.WARN, "Channel reuse attempt ${attempt + 1} failed: result1 code = ${result1?.code()}, result2 code = ${result2?.code()}. Retrying...")
143-
} catch (Throwable t) {
144-
logger.log(LogLevel.WARN, "Channel reuse attempt ${attempt + 1} caught exception: ${t.message}. Retrying...", t)
152+
if (result1 != null) {
153+
try {
154+
result1Body = result1.body().string()
155+
} catch (Exception e) {
156+
result1Body = "Error reading body: " + e.getMessage()
157+
}
158+
}
159+
if (result2 != null) {
160+
try {
161+
result2Body = result2.body().string()
162+
} catch (Exception e) {
163+
result2Body = "Error reading body: " + e.getMessage()
164+
}
165+
}
166+
logger.log(LogLevel.WARN, "Channel reuse attempt ${attempt + 1} failed: result1 code = ${lastResult1Code} (body: ${result1Body}), result2 code = ${lastResult2Code} (body: ${result2Body}). Retrying...")
167+
} catch (Exception e) {
168+
logger.log(LogLevel.WARN, "Channel reuse attempt ${attempt + 1} caught exception: ${e.message}. Retrying...", e)
169+
} finally {
170+
if (result1 != null) {
171+
try { result1.body().close() } catch (Exception ignored) {}
172+
result1 = null
173+
}
174+
if (result2 != null) {
175+
try { result2.body().close() } catch (Exception ignored) {}
176+
result2 = null
177+
}
145178
}
146179
Thread.sleep(2000)
147180
}
148-
if (result1 == null || result2 == null || result1.code() != 200 || result2.code() != 200) {
149-
if (result1 != null) {
150-
result1Body = result1.body().string()
151-
}
152-
if (result2 != null) {
153-
result2Body = result2.body().string()
154-
}
155-
throw new GradleException("Unable to reuse same channel across requests. result1: ${result1?.code()} (body: ${result1Body}), result2: ${result2?.code()} (body: ${result2Body})")
181+
if (!success) {
182+
throw new GradleException("Unable to reuse same channel across requests. result1: ${lastResult1Code} (body: ${result1Body}), result2: ${lastResult2Code} (body: ${result2Body})")
156183
}
157184

158185
// The test suite can take a while to run

0 commit comments

Comments
 (0)