Activities run in tests using `TestActivityEnvironment` intermittently fails with `java.util.concurrent.TimeoutException`


I have been recently testing a couple of Temporal Activities using TestActivityEnvironment after adding heart-beating to them. Then suddenly, I started seeing irregular failures of those activity calls during test runs on Jenkins. It happened not as frequently, could not be produced locally, and went away after a single or couple of reruns, so I didn’t care much. On my PR from 2 days ago, however, which is completely unrelated to how the Activities run, I started seeing the timeout error happening on 2-3 JUnit tests repeatedly, always erroring out on one (which changes), and happening over 10+ test runs until now.

Since it’s not reproducible locally, I’m not sure if this is caused by how things are setup on the remote Jenkins. But the problem is, it’s always coming off of the TestActivityEnvironment.

This is the error message I’m repeatedly seeing from different Temporal Activity runs on different tests:

java.lang.RuntimeException at
        Caused by: java.util.concurrent.TimeoutException at

Does this look familiar to anyone? Was anyone able to fix this issue?

I guess that your CI/CD environment is so resource-constrained that it is not able to submit the task to the executor here. I would try to give it more CPU/Memory.

It looks like the test framework expects activities to complete under 10 seconds.

      Future<Result> activityFuture =
              () ->
                      new ActivityTask(activityTask, () -> {}),

      try {
        // 10 seconds is just a "reasonable" wait to not make an infinite waiting
        return activityFuture.get(10, TimeUnit.SECONDS);
      } catch (InterruptedException e) {

I’m not sure why this is hardcoded to this value. May be the author expected unit tests to run fast.
Let me fix this.

1 Like

Pull Request for the fix: Removed heardcoded 10 second timeout for an activity under test by mfateev · Pull Request #1957 · temporalio/sdk-java · GitHub

1 Like