Integration test to verify all tests are run on the same thread under @RunWith.

Summary:
Updated `DelegateRunnerWithTimeout` so that it maintains the default behavior of
JUnit where all tests are run on the same thread. We observed some test cases in
the wild that relied on this behavior. Specifically, Robolectric tests rely on this
due to a check in `org.robolectric.shadows.ShadowLooper`.

Test Plan:
Add a test to the `RunWithDefaultTimeoutIntegrationTest` test case to exercise the fix.
Made `executor` an instance rather than a `DelegateRunnerWithTimeout` field and verified
that `RunWithDefaultTimeoutIntegrationTest#testAllTestsForRunWithAreRunOnTheSameThread()`
failed.
diff --git a/test/com/facebook/buck/junit/RunWithDefaultTimeoutIntegrationTest.java b/test/com/facebook/buck/junit/RunWithDefaultTimeoutIntegrationTest.java
index 0798174..46bc7ce 100644
--- a/test/com/facebook/buck/junit/RunWithDefaultTimeoutIntegrationTest.java
+++ b/test/com/facebook/buck/junit/RunWithDefaultTimeoutIntegrationTest.java
@@ -99,4 +99,14 @@
     testResult.assertExitCode(0);
   }
 
+  @Test
+  public void testAllTestsForRunWithAreRunOnTheSameThread() throws IOException {
+    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
+        this, "run_with_timeout", temporaryFolder);
+    workspace.setUp();
+
+    ProcessResult testResult = workspace.runBuckCommand("test",
+        "//:MultipleTestsThatExpectToBeAbleToReuseTheMainThread");
+    testResult.assertExitCode(0);
+  }
 }
diff --git a/test/com/facebook/buck/junit/testdata/run_with_timeout/BUCK b/test/com/facebook/buck/junit/testdata/run_with_timeout/BUCK
index e64c201..46c7e6e 100644
--- a/test/com/facebook/buck/junit/testdata/run_with_timeout/BUCK
+++ b/test/com/facebook/buck/junit/testdata/run_with_timeout/BUCK
@@ -42,6 +42,24 @@
   ],
 )
 
+java_library(
+  name = 'UtilityThatHoldsAReferenceToTheMainThread',
+  srcs = [ 'UtilityThatHoldsAReferenceToTheMainThread.java', ],
+)
+
+java_test(
+  name = 'MultipleTestsThatExpectToBeAbleToReuseTheMainThread',
+  srcs = [
+    'Test1.java',
+    'Test2.java',
+  ],
+  deps = [
+    ':junit',
+    ':NotBuckBlockJUnit4ClassRunner',
+    ':UtilityThatHoldsAReferenceToTheMainThread',
+  ],
+)
+
 prebuilt_jar(
   name = 'junit',
   binary_jar = 'junit-4.11.jar',
diff --git a/test/com/facebook/buck/junit/testdata/run_with_timeout/Test1.java b/test/com/facebook/buck/junit/testdata/run_with_timeout/Test1.java
new file mode 100644
index 0000000..b926a9e
--- /dev/null
+++ b/test/com/facebook/buck/junit/testdata/run_with_timeout/Test1.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2013-present Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.example;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(NotBuckBlockJUnit4ClassRunner.class)
+public class Test1 {
+
+  @Test
+  public void test() {
+    UtilityThatHoldsAReferenceToTheMainThread.resetThreadLoopers();
+  }
+}
diff --git a/test/com/facebook/buck/junit/testdata/run_with_timeout/Test2.java b/test/com/facebook/buck/junit/testdata/run_with_timeout/Test2.java
new file mode 100644
index 0000000..c97a224
--- /dev/null
+++ b/test/com/facebook/buck/junit/testdata/run_with_timeout/Test2.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2013-present Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.example;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(NotBuckBlockJUnit4ClassRunner.class)
+public class Test2 {
+
+  @Test
+  public void test() {
+    UtilityThatHoldsAReferenceToTheMainThread.resetThreadLoopers();
+  }
+}
diff --git a/test/com/facebook/buck/junit/testdata/run_with_timeout/UtilityThatHoldsAReferenceToTheMainThread.java b/test/com/facebook/buck/junit/testdata/run_with_timeout/UtilityThatHoldsAReferenceToTheMainThread.java
new file mode 100644
index 0000000..8d0aed5
--- /dev/null
+++ b/test/com/facebook/buck/junit/testdata/run_with_timeout/UtilityThatHoldsAReferenceToTheMainThread.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2013-present Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.example;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Here is a utility that exercises the problematic behavior in
+ * {@code org.robolectric.shadows.ShadowLooper} where a reference to the thread that was used to
+ * load the class is stored and assumed to be the main thread. Because there is a check that asserts
+ * that the current thread (i.e., the thread on which the test is run) is the "main thread" (which
+ * again, is assumed to be the thread that was used to load the class), that means that we cannot
+ * set up the test runner on one thread and then run the tests on different threads when using the
+ * {@code ShadowLooper} in Robolectric.
+ * <p>
+ * This is an issue because our {@link DelegateRunnerWithTimeout} does not run tests on the main
+ * thread: it uses a {@link ExecutorService} that can be shutdown if a test exceeds its timeout.
+ * So long as everything happens on the {@link ExecutorService}'s single thread, everything should
+ * be fine.
+ */
+class UtilityThatHoldsAReferenceToTheMainThread {
+
+  private static final Thread MAIN_THREAD = Thread.currentThread();
+
+  public static synchronized void resetThreadLoopers() {
+    if (Thread.currentThread() != MAIN_THREAD) {
+      throw new RuntimeException("This is expected to be called from the main thread.");
+    }
+  }
+}