Repository navigation
Time Skipping V2 - #1959
Time Skipping V2#1959
Conversation
…hild_workflow_propagates_time_skipping
…t_forward_then_unbounded, which is now failing
| Workflows started via :py:attr:`client` during the block do not | ||
| receive a ``time_skipping_config`` on their start request. Existing | ||
| workflows and V1 auto-behavior are unaffected. No-op on non-V2 | ||
| environments. |
There was a problem hiding this comment.
This seems to say the same thing.
There was a problem hiding this comment.
Maybe redundant, but I want to keep it since it's specific about exactly what is being suspended
There was a problem hiding this comment.
I just don't understand it. What's the difference between unaffected and noop?
There was a problem hiding this comment.
Yeah, the V1 mention is redundant. Changed to "Existing workflows are unaffected. No-op on non-V2 environments." 'Unaffected' means it doesn't affect already-started workflows, vs "no-op" meaning on non-v2 it does nothing at all.
|
|
||
| async def get_current_time( | ||
| self, | ||
| handle: temporalio.client.WorkflowHandle[Any, Any] | None = None, |
There was a problem hiding this comment.
I don't love this being optional but required at runtime for v2. Is there anything we can do, like getting the handle from the context by default or something like that?
There was a problem hiding this comment.
I think the best we can do here is to use the sole handle, if there is only one, but I don't really like the idea that if you add another workflow (or more likely copy a single-workflow test and add another workflow, or SAA, or schedule) it will surprisingly fail. I want to emphasize that V2 has a different clock for every workflow (or SAA or schedule) and you have to be specific about it.
Making it required here will force the user to fix it during migration and mostly confine the learning process to that.
There was a problem hiding this comment.
Maybe when we deprecate/remove v1, we can make the handle required on the type.
Time Skipping V2
Per-workflow virtual-clock time skipping for the Python SDK. An alternative to
the V1 Java test server, has a single global virtual clock and does not run on
Linux or Windows ARM.
Public API
Testing-env entry points on
temporalio.testing.WorkflowEnvironment:WorkflowEnvironment.start_time_skipping_v2(...)— start a CLI dev serverwith time skipping enabled; return an environment whose client adds
TimeSkippingConfigto every workflow it starts.env.fast_forward(handle, duration=None)— advance one workflow's virtualclock by a
timedelta/float, or (withNone) skip to termination.Returns
Trueon completion,Falsewhen the workflow terminates first,raises
RuntimeErrorwhen a later fast-forward supersedes it.env.get_current_time(handle)— read a workflow's current virtual time.env.get_time_skipping_info(handle)— fetchTimeSkippingInfo(effective config, current time, in-flight fast-forward).
env.with_time_skipping_disabled()— context manager that suspendstime skipping on new
start_workflowcalls inside the block.env.supports_time_skipping_v1/env.supports_time_skipping_v2.Direct, non-test entry points on
temporalio.testing:TimeSkipper(client, config=TimeSkippingConfig(...))— wrap an existingClientwith per-workflow time skipping.TimeSkippingConfig(enabled, fast_forward_config, disable_propagation, max_session_skip_count).FastForwardConfig(id, duration).Example — test environment
Tests
tests/testing/test_timeskipping_v2.py(dedicated V2 behavior).tests/worker/test_workflow.py(a_ts_v2version oftest_workflow_cancel_signal_and_timer_fired_in_same_task, addedalongside the V1 version in the same file).
tests/testing/test_workflow.py(
test_get_time_skipping_info_raises_on_non_ts_v2_env).tests/testing/test_workflow_ts_v2.py:three ports of V1 tests (
basic,manual,disabled) plus one new case(
basic_via_update_v2). The V1heartbeat_timeouttest is deliberatelynot ported since it relies on V1-specific behavior.