cloudfoundry / bosh-linux-stemcell-builder

BOSH Ubuntu Linux stemcells
Apache License 2.0
42 stars 103 forks source link

Prevent early deletion of temp files in specs #377

Closed ystros closed 3 months ago

ystros commented 3 months ago

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.