Skip to content

Commit

Permalink
Return to previous date after block when in threadsafe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-lord authored and joshuacronemeyer committed Feb 5, 2021
1 parent 589e515 commit e75a43c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/timecop/timecop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def travel(mock_type, *args, &block) #:nodoc:
begin
yield stack_item.time
ensure
@stack.replace stack_backup
stack.replace stack_backup
@safe = safe_backup
end
end
Expand Down
12 changes: 11 additions & 1 deletion test/timecop_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def test_not_frozen_after_return
assert !Timecop.frozen?
end

def test_thread_safe_timecop
def test_thread_safe_timecop_in_parallel
Timecop.thread_safe = true
date = Time.local(2011, 01, 02)
thread = Thread.new do
Expand All @@ -567,6 +567,16 @@ def test_thread_safe_timecop
Timecop.thread_safe = false
end

def test_thread_safe_timecop_returns_after_block
Timecop.thread_safe = true
date = Time.local(2017, 10, 8)

Timecop.freeze(date) { }
assert Time.now != date
ensure
Timecop.thread_safe = false
end

private

def with_safe_mode(enabled=true)
Expand Down

0 comments on commit e75a43c

Please sign in to comment.