Skip to content

Commit a3a7e9c

Browse files
committed
Split slow tests for speed
1 parent 9142f0a commit a3a7e9c

2 files changed

Lines changed: 80 additions & 12 deletions

File tree

temporal-sdk/src/test/java/io/temporal/client/functional/GetActivityResultOverServerLongPollWaitTest.java renamed to temporal-sdk/src/test/java/io/temporal/client/functional/GetActivityResultAsyncOverServerLongPollWaitTest.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
import org.junit.Test;
1717

1818
/**
19-
* Verifies that {@link ActivityHandle#getResult()} and {@link ActivityHandle#getResultAsync()}
20-
* continue polling after the server cuts a long poll and returns an empty response. The server cuts
21-
* activity long polls after approximately {@value ACTIVITY_LONG_POLL_TIMEOUT_SECONDS} seconds; the
22-
* activity here runs for 1.5× that so the server-side cut fires at least once before the activity
23-
* completes.
19+
* Verifies that {@link ActivityHandle#getResultAsync()} continues polling after the server cuts a
20+
* long poll and returns an empty response. The server cuts activity long polls after approximately
21+
* {@value ACTIVITY_LONG_POLL_TIMEOUT_SECONDS} seconds; the activity here runs for 1.5× that so the
22+
* server-side cut fires at least once before the activity completes.
23+
*
24+
* <p>It has a sync version in {@link GetActivityResultSyncOverServerLongPollWaitTest} that is split
25+
* to reduce the total execution time.
2426
*/
25-
public class GetActivityResultOverServerLongPollWaitTest {
27+
public class GetActivityResultAsyncOverServerLongPollWaitTest {
2628
private static final int ACTIVITY_LONG_POLL_TIMEOUT_SECONDS = 20;
2729

2830
@ActivityInterface
@@ -63,12 +65,6 @@ private StartActivityOptions slowOpts() {
6365
.build();
6466
}
6567

66-
@Test(timeout = 2 * ACTIVITY_LONG_POLL_TIMEOUT_SECONDS * 1000)
67-
public void testGetResult() {
68-
assumeTrue(SDKTestWorkflowRule.useExternalService);
69-
newActivityClient().execute(SlowActivity.class, SlowActivity::run, slowOpts());
70-
}
71-
7268
@Test(timeout = 2 * ACTIVITY_LONG_POLL_TIMEOUT_SECONDS * 1000)
7369
public void testGetResultAsync() throws ExecutionException, InterruptedException {
7470
assumeTrue(SDKTestWorkflowRule.useExternalService);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package io.temporal.client.functional;
2+
3+
import static org.junit.Assume.assumeTrue;
4+
5+
import io.temporal.activity.ActivityInterface;
6+
import io.temporal.activity.ActivityMethod;
7+
import io.temporal.client.ActivityClient;
8+
import io.temporal.client.ActivityClientOptions;
9+
import io.temporal.client.ActivityHandle;
10+
import io.temporal.client.StartActivityOptions;
11+
import io.temporal.testing.internal.SDKTestWorkflowRule;
12+
import java.time.Duration;
13+
import java.util.UUID;
14+
import org.junit.Rule;
15+
import org.junit.Test;
16+
17+
/**
18+
* Verifies that {@link ActivityHandle#getResult()} continues polling after the server cuts a long
19+
* poll and returns an empty response. The server cuts activity long polls after approximately
20+
* {@value ACTIVITY_LONG_POLL_TIMEOUT_SECONDS} seconds; the activity here runs for 1.5× that so the
21+
* server-side cut fires at least once before the activity completes.
22+
*
23+
* <p>It has an async version in {@link GetActivityResultAsyncOverServerLongPollWaitTest} that is
24+
* split to reduce the total execution time.
25+
*/
26+
public class GetActivityResultSyncOverServerLongPollWaitTest {
27+
private static final int ACTIVITY_LONG_POLL_TIMEOUT_SECONDS = 20;
28+
29+
@ActivityInterface
30+
public interface SlowActivity {
31+
@ActivityMethod(name = "SlowActivity")
32+
void run();
33+
}
34+
35+
public static class SlowActivityImpl implements SlowActivity {
36+
@Override
37+
public void run() {
38+
try {
39+
Thread.sleep(Duration.ofSeconds(3 * ACTIVITY_LONG_POLL_TIMEOUT_SECONDS / 2).toMillis());
40+
} catch (InterruptedException e) {
41+
Thread.currentThread().interrupt();
42+
}
43+
}
44+
}
45+
46+
@Rule
47+
public SDKTestWorkflowRule testWorkflowRule =
48+
SDKTestWorkflowRule.newBuilder()
49+
.setUseTimeskipping(false)
50+
.setActivityImplementations(new SlowActivityImpl())
51+
.build();
52+
53+
private ActivityClient newActivityClient() {
54+
return ActivityClient.newInstance(
55+
testWorkflowRule.getWorkflowClient().getWorkflowServiceStubs(),
56+
ActivityClientOptions.newBuilder().setNamespace(SDKTestWorkflowRule.NAMESPACE).build());
57+
}
58+
59+
private StartActivityOptions slowOpts() {
60+
return StartActivityOptions.newBuilder()
61+
.setId("slow-act-" + UUID.randomUUID())
62+
.setTaskQueue(testWorkflowRule.getTaskQueue())
63+
.setScheduleToCloseTimeout(Duration.ofMinutes(2))
64+
.build();
65+
}
66+
67+
@Test(timeout = 2 * ACTIVITY_LONG_POLL_TIMEOUT_SECONDS * 1000)
68+
public void testGetResult() {
69+
assumeTrue(SDKTestWorkflowRule.useExternalService);
70+
newActivityClient().execute(SlowActivity.class, SlowActivity::run, slowOpts());
71+
}
72+
}

0 commit comments

Comments
 (0)