Skip to content

Commit 302bf6b

Browse files
committed
Add "throws Throwable" to executeTest() signature.
Tweaked handling of interrupt to main thread.
1 parent d428e9c commit 302bf6b

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

BevoTest/src/edu/utexas/cs/bevotest/BevoTest.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ protected void addTestCase(final TestCase<?, ?> testCase) {
129129
* @param log the <code>TestLog</code> in which the test results will
130130
* be recorded
131131
* @throws InterruptedException if the test framework thread is
132-
* interrupted
132+
* interrupted. The <i>interrupted
133+
* status</i> of the current thread is
134+
* cleared when this exception is
135+
* thrown.
133136
*/
134137
public void run(final TestLog log) throws InterruptedException {
135138
try {
@@ -259,11 +262,18 @@ protected void setTimeOut(final long timeOutMs) {
259262
* @param testLog the <code>TestLog</code> in which to record the
260263
* test execution results
261264
* @throws InterruptedException if the test framework thread is
262-
* interrupted
265+
* interrupted. The <i>interrupted
266+
* status</i> of the current thread is
267+
* cleared when this exception is
268+
* thrown.
263269
*/
264270
public void run(final TestLog testLog) throws InterruptedException {
265271
final TestExecutionResult<C, R> logEntry = new TestExecutionResult<C, R>(testLog, this);
266272

273+
if (Thread.interrupted()) {
274+
throw new InterruptedException("test run interrupted");
275+
}
276+
267277
if (shouldSkip()) {
268278
logEntry.skipped();
269279
return;
@@ -302,7 +312,13 @@ public void run() {
302312
};
303313
/* TODO: Capture stdout, stderr, and jul logging records, too? */
304314
t.start();
305-
t.join(getTimeOut());
315+
try {
316+
t.join(getTimeOut());
317+
} catch (InterruptedException e) {
318+
/* Interrupted while waiting for test; interrupt test and exit */
319+
tg.interrupt();
320+
throw e;
321+
}
306322
ensureThreadGroupTerminated(logEntry, tg, t);
307323
if (!tg.isDestroyed()) {
308324
tg.destroy();
@@ -385,14 +401,14 @@ public boolean shouldSkip() {
385401

386402
protected void initiate(final TestExecutionResult<C, R> logEntry) throws InterruptedException {
387403
if (Thread.interrupted()) {
388-
throw new InterruptedException();
404+
throw new InterruptedException("test initiation interrupted");
389405
}
390406
logEntry.settingUp();
391407
}
392408

393409
private static InheritableThreadLocal<TestExecutionResult<?, ?>> logEntryTL = new InheritableThreadLocal<TestExecutionResult<?, ?>>();
394410

395-
protected void executeTest(final TestExecutionResult<C, R> logEntry) {
411+
protected void executeTest(final TestExecutionResult<C, R> logEntry) throws Throwable {
396412
logEntryTL.set(logEntry);
397413
executeTest();
398414
}
@@ -411,7 +427,7 @@ protected void executeTest(final TestExecutionResult<C, R> logEntry) {
411427
* Exceptions thrown by <code>executeTest()</code> will be recorded,
412428
* and the test will be considered completed.
413429
*/
414-
abstract protected void executeTest();
430+
abstract protected void executeTest() throws Throwable;
415431

416432
protected void starting(final C instanceUnderTest, final TestExecutionResult<C, R> logEntry) {
417433
if (instanceUnderTest == null) {
@@ -572,8 +588,7 @@ public TestThrows(final Test test, final Class<C> classUnderTest, final String d
572588
* A <code>TestLog</code> is a record of an execution of a
573589
* <code>Test</code>. It consists of a sequence of
574590
* <code>TestLogEntries</code>, some test environment data, and some
575-
* summary test execution data (such as start time). A <code>TestLog</code>
576-
* can produce a detailed or summary test report.
591+
* summary test execution data (such as start time).
577592
*
578593
* @author John Thywissen
579594
*/
@@ -751,9 +766,7 @@ public interface TestLogEntry {
751766
* test case on a test item. Each <code>TestExecutionResult</code>
752767
* has a status (running, complete, etc...) and evaluation (pass/fail),
753768
* along with details of the execution. These details include the
754-
* runtime type of the test item, test results, and run time. A
755-
* <code>TestExecutionResult</code> can produce a detailed report of the
756-
* test results.
769+
* runtime type of the test item, test results, and run time.
757770
*
758771
* @author John Thywissen
759772
* @param <C> the Class type instance of the test item
@@ -946,6 +959,7 @@ protected void tearingDown() throws IllegalStateException {
946959
}
947960

948961
protected void caught(final Throwable t) {
962+
//assert caughtValue == null;
949963
caughtValue = t;
950964
setStatus(Status.COMPLETE_ABNORMAL);
951965
}

0 commit comments

Comments
 (0)