Skip to content

Fail specs that inherit a leaked Timecop clock - #5511

Open
philippthun wants to merge 1 commit into
cloudfoundry:mainfrom
sap-contributions:add-timecop-leak-guard
Open

philippthun wants to merge 1 commit into
cloudfoundry:mainfrom
sap-contributions:add-timecop-leak-guard

Conversation

@philippthun

@philippthun philippthun commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

A spec that freezes or travels time without returning it corrupts every following example that derives a value from Time.now, such as the decorator specs that set created_at to Time.now.utc - 1.second to assert an ordering. The leaked clock reverses that ordering, producing flaky failures far from the spec that actually leaked.

The global after(:each) that returns time silently absorbs such a leak. Add a prepend_before that detects an already-active Timecop clock at example entry and fails immediately, naming the example that inherited the leak so the real culprit can be bisected out.

This change was developed with AI assistance; all code was reviewed and tested by me.

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

A spec that freezes or travels time without returning it corrupts every
following example that derives a value from Time.now, such as the
decorator specs that set created_at to Time.now.utc - 1.second to assert
an ordering. The leaked clock reverses that ordering, producing flaky
failures far from the spec that actually leaked.

The global after(:each) that returns time silently absorbs such a leak.
Add a prepend_before that detects an already-active Timecop clock at
example entry and fails immediately, naming the example that inherited
the leak so the real culprit can be bisected out.
@philippthun
philippthun force-pushed the add-timecop-leak-guard branch from b717ba3 to a491da6 Compare October 6, 2026 11:04

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant