Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent early deletion of temp files in specs #377

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

ystros
Copy link
Contributor

@ystros ystros commented Aug 21, 2024

After upgrading the bosh/integration image from Ruby 3.2 to 3.3, the shellout types unit spec began frequently failing with errors like:

expected RuntimeError with "group 65627 does not exist", got #<RuntimeError:"stat: cannot statx 'a-file20240815-267-utzwlo': No such file or directory\n">

It seems that Ruby 3.3 is much more aggressive about garbage collection. Several of the Tempfiles created in this spec were referenced only locally in a let definition, merely passing their path to the actual object returned by the let. Since the Tempfile object itself was no longer being referenced, it would be garbage collected and the file on disk deleted. Other lets that returned the Tempfile directly did not have this problem.

Now, all usages of Tempfile are defined in their own let, allowing the file to exist until after the test has finished running.

After upgrading the bosh/integration image from Ruby 3.2 to 3.3, the
shellout types unit spec began frequently failing with errors like:
```
expected RuntimeError with "group 65627 does not exist", got #<RuntimeError:"stat: cannot statx 'a-file20240815-267-utzwlo': No such file or directory\n">
```

It seems that Ruby 3.3 is much more aggressive about garbage collection.
Several of the Tempfiles created in this spec were referenced only
locally in a `let` definition, merely passing their path to the actual
object returned by the `let`. Since the Tempfile object itself was no
longer being referenced, it would be garbage collected and the file on
disk deleted. Other `let`s that returned the Tempfile directly did not
have this problem.

Now, all usages of Tempfile are defined in their own `let`, allowing the
file to exist until after the test has finished running.
@jpalermo jpalermo merged commit 92d6c7f into ubuntu-jammy Aug 22, 2024
1 check passed
@jpalermo jpalermo deleted the fix-tempfile-garbage-collection branch August 22, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

4 participants