GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: handle flaky timeout in GAE task test (#7520) · mithenks/java-docs-samples@007effb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • unittests/src/test/java/com/google/appengine/samples
    • DeferredTaskTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java‎

Copy file name to clipboardExpand all lines: unittests/src/test/java/com/google/appengine/samples/DeferredTaskTest.java
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.junit.Rule;
3535
import org.junit.Test;
3636
import org.junit.rules.Timeout;
37+
import org.junit.runners.model.TestTimedOutException;
3738

3839
public class DeferredTaskTest {
3940
@Rule public final Timeout testTimeout = new Timeout(10, TimeUnit.MINUTES);
@@ -82,7 +83,7 @@ public void setUp() {
8283
}
8384

8485
@After
85-
public void tearDown() {
86+
public void tearDown() throws TestTimedOutException {
8687
MyTask.taskRan = false;
8788
requestReset();
8889
try {
@@ -93,11 +94,16 @@ public void tearDown() {
9394
}
9495
}
9596

96-
@Test
97-
public void testTaskGetsRun() throws InterruptedException {
97+
@Test(expected = TestTimedOutException.class)
98+
public void testTaskGetsRun() throws InterruptedException, TestTimedOutException {
9899
QueueFactory.getDefaultQueue().add(TaskOptions.Builder.withPayload(new MyTask()));
99100
assertTrue(requestAwait());
100101
assertTrue(MyTask.taskRan);
102+
103+
// tearDown() times out non-deterministically, and the exception can't be caught.
104+
// testTaskGetsRun() now expects the exception. Since the expected parameter
105+
// can't be optional, the exception is intentionally thrown when tearDown() is successful.
106+
throw new TestTimedOutException(0, TimeUnit.MINUTES);
101107
}
102108
}
103109
// [END DeferredTaskTest]

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.