gae-interop-testing: create new instance per test for okhttp (#3698)

Without this, the test is flakey for some test methods. The flakiness
is probably caused by AbstractInteropTest and not due to gRPC itself.
This commit is contained in:
zpencer 2017-11-09 16:07:58 -08:00 committed by GitHub
parent 1a42a4c921
commit 970785d82b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -60,12 +60,11 @@ public final class OkHttpClientInteropServlet extends HttpServlet {
// We can not use JUnit because it tries to spawn backgrounds threads. // We can not use JUnit because it tries to spawn backgrounds threads.
// GAE+JDK7 does not allow arbitrary background threads. // GAE+JDK7 does not allow arbitrary background threads.
// Let's use reflection to run test methods. // Let's use reflection to run test methods.
Tester tester = new Tester();
List<Method> befores = new ArrayList<>(); List<Method> befores = new ArrayList<>();
List<Method> afters = new ArrayList<>(); List<Method> afters = new ArrayList<>();
List<Method> testMethods = new ArrayList<>(); List<Method> testMethods = new ArrayList<>();
int ignored = 0; int ignored = 0;
for (Method method : tester.getClass().getMethods()) { for (Method method : Tester.class.getMethods()) {
if (method.getAnnotation(Test.class) != null) { if (method.getAnnotation(Test.class) != null) {
if (method.getAnnotation(Ignore.class) != null) { if (method.getAnnotation(Ignore.class) != null) {
ignored++; ignored++;
@ -82,6 +81,8 @@ public final class OkHttpClientInteropServlet extends HttpServlet {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int failures = 0; int failures = 0;
for (Method method : testMethods) { for (Method method : testMethods) {
// JUnit creates a new instance per test method, we will emulate that behavior.
Tester tester = new Tester();
try { try {
for (Method before : befores) { for (Method before : befores) {
before.invoke(tester); before.invoke(tester);