diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 889d173..7f941aa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -126,9 +126,13 @@ def set_hieradata(hieradata) end end - File.open(c.hiera_config, 'w') do |f| - f.write data.to_yaml - end + # Write atomically (write + rename) — every parallel_spec worker runs + # this hook, and a truncating write here can be observed as an empty + # hiera.yaml by a catalogue compile in another worker, silently dropping + # all custom hieradata (simp/pupmod-simp-simplib#362) + tmpfile = "#{c.hiera_config}.#{Process.pid}" + File.write(tmpfile, data.to_yaml) + File.rename(tmpfile, c.hiera_config) end # rubocop:enable RSpec/BeforeAfterAll