diff --git a/temporalio/lib/temporalio/testing/workflow_environment.rb b/temporalio/lib/temporalio/testing/workflow_environment.rb index 26804afa..569370e1 100644 --- a/temporalio/lib/temporalio/testing/workflow_environment.rb +++ b/temporalio/lib/temporalio/testing/workflow_environment.rb @@ -322,7 +322,7 @@ def auto_time_skipping_disabled(&) raise 'Block required' unless block_given? return super unless supports_time_skipping? - already_disabled = @auto_time_skipping + already_disabled = !@auto_time_skipping @auto_time_skipping = false begin yield diff --git a/temporalio/test/testing/workflow_environment_test.rb b/temporalio/test/testing/workflow_environment_test.rb index aebc231d..e8ebc967 100644 --- a/temporalio/test/testing/workflow_environment_test.rb +++ b/temporalio/test/testing/workflow_environment_test.rb @@ -55,6 +55,34 @@ def test_time_skipping_auto end end + def test_auto_time_skipping_disabled + skip_if_not_x86! + Temporalio::Testing::WorkflowEnvironment.start_time_skipping(logger: Logger.new($stdout)) do |env| + worker = Temporalio::Worker.new( + client: env.client, + task_queue: "tq-#{SecureRandom.uuid}", + workflows: [SlowWorkflow] + ) + worker.run do + # Check that timestamp is around now + assert_in_delta(Time.now, env.current_time, 30.0) + + # Run workflow + handle = env.client.start_workflow( + SlowWorkflow, + id: "wf-#{SecureRandom.uuid}", + task_queue: worker.task_queue + ) + env.auto_time_skipping_disabled do + handle.signal(SlowWorkflow.some_signal) + end + # Check that timestamp is now about two days from now + assert_equal 'all done', handle.result + assert_in_delta Time.now + SlowWorkflow::TWO_DAYS, env.current_time, 30.0 + end + end + end + def test_time_skipping_manual skip_if_not_x86! Temporalio::Testing::WorkflowEnvironment.start_time_skipping(logger: Logger.new($stdout)) do |env|