# TestWorkflowEnvironment doesn't respect activity ScheduleToCloseTimeout

**URL:** <https://community.temporal.io/t/testworkflowenvironment-doesnt-respect-activity-scheduletoclosetimeout/17289>\
**Category:** Community Support\
**Tags:** java-sdk, testing, timeout\
**Created:** [May 1, 2025, 10:57am UTC](https://community.temporal.io/t/testworkflowenvironment-doesnt-respect-activity-scheduletoclosetimeout/17289 "2025-05-01T10:57:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew1](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/andrew1/32/7208_2.png) [@Andrew1](https://community.temporal.io/u/Andrew1)\
**Post date:** [May 1, 2025, 10:57am UTC](https://community.temporal.io/t/testworkflowenvironment-doesnt-respect-activity-scheduletoclosetimeout/17289/1 "2025-05-01T10:57:38Z")

</div>

In about 0,1% cases `TestWorkflowEnvironment` doesn’t respect activity `ScheduleToCloseTimeout` and retries it infinitely, which leads to test’s failures.

Activity stub has settings:

- ScheduleToCloseTimeout = 30 seconds
- MaximumAttempts = 0
- BackoffCoefficient = 1
- InitialInterval = 5 seconds

Usual run looks like this:

```auto
Before run: Thu May 01 11:15:06 CEST 2025
Attempt 1 scheduled at: Thu May 01 11:15:06 CEST 2025
...
Attempt 6 scheduled at: Thu May 01 11:15:26 CEST 2025
After run: Thu May 01 11:15:41 CEST 2025

```

Because of time skipping test takes \< 1 seconds.

However about 0,1% or runs look like this:

```auto
Before run: Thu May 01 11:15:06 CEST 2025
Attempt 1 scheduled at: Thu May 01 11:15:06 CEST 2025
...
Attempt 24454 scheduled at: Fri May 02 21:18:51 CEST 2025
java.util.concurrent.TimeoutException: executeTest() timed out after 30 seconds

```

Although \> 24 hours of temporal time is passed since first activity attempt, temporalio doesn’t fails activity, which leads to test timeout.

Increasing test timeout to 60 seconds doesn’t help, so issue is not caused by temporal VS real time thing.

MVE:

> **[GitHub - AUlasen/temporalio-test-timeout-mve](https://github.com/AUlasen/temporalio-test-timeout-mve)**
>
> Contribute to AUlasen/temporalio-test-timeout-mve development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [July 20, 2025, 4:26pm UTC](https://community.temporal.io/t/testworkflowenvironment-doesnt-respect-activity-scheduletoclosetimeout/17289/2 "2025-07-20T16:26:32Z")

</div>

Thanks for reporting (sorry for late response).  
Can you [update](https://github.com/AUlasen/temporalio-test-timeout-mve/blob/master/pom.xml#L47) your pom to [latest](https://github.com/temporalio/sdk-java/releases/tag/v1.30.1) sdk version and see if you run into same problem?

Can you try also without using the [explicitly defined retry policy](https://github.com/temporalio/sdk-java/releases/tag/v1.30.1), just set ScheduleToClose timeout. Another idea could be to reuse your testEnv rather than creating a new one for each test. Its pretty expensive to create test env and wondering if its some sort of possible issue with resource utilization on your laptop or similar that could be involved too

---

<div class="post-metadata">

**Author:** ![Andrew1](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/andrew1/32/7208_2.png) [@Andrew1](https://community.temporal.io/u/Andrew1)\
**Post date:** [July 27, 2025, 11:58am UTC](https://community.temporal.io/t/testworkflowenvironment-doesnt-respect-activity-scheduletoclosetimeout/17289/3 "2025-07-27T11:58:11Z")

</div>

Hey Tihomir!  
Tried all - still the same issue. Updated [repo](https://github.com/AUlasen/temporalio-test-timeout-mve)
