sdk-java icon indicating copy to clipboard operation
sdk-java copied to clipboard

Provide a way to set Heartbeat details in TestActivityEnvironment

Open tylercunnion opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe. It doesn't seem easy (or possible) to test Activity methods which make use of HeartbeatDetails for resuming an aborted process, etc. The TestActivityEnvironment does not allow for Activity retries (all exceptions are set to non-retryable), and there is no method for "faking" a previous heartbeat call before calling the Activity method under test.

Describe the solution you'd like I'd like to be able to call a method to simulate a previous heartbeat. Whatever mechanism this is would have to be accessible from the executeActivity method here. Since the only real externally-facing part of the test environment is the TestActivityEnvironment object itself, that would probably be the place to hook into. We'd have to add something like a setHeartbeatDetails with parameters indicating the Activity name to apply this heartbeat to as well as the heartbeat payload. Then, inside executeActivity it would call a getHeartbeatDetails for the given Activity name which would return the heartbeat payload and clear the buffer. (Definitely not married to any of the specifics here, just my initial thought)

Describe alternatives you've considered Allowing the TestActivityEnvironment to retry Activity executions could also work, as long as heartbeats are persisted and available to the retry as normal. The final option would be to work around this entirely and use TestWorkflowEnvironment together with an ad-hoc Workflow that only executes the Activity being tested.

tylercunnion avatar Jul 16 '22 01:07 tylercunnion

+1. Have a long-running activity that resumes from a previous heartbeat's checkpoint and it's difficult or not possible to test.

Bennett-Lynch avatar Sep 07 '22 20:09 Bennett-Lynch