From 581aaaf95563587d78fb9aad4d4fc42da88a10d0 Mon Sep 17 00:00:00 2001 From: Steven Pritchard Date: Mon, 24 Aug 2026 14:52:32 +0000 Subject: [PATCH] [puppetsync] Fix hiera.yaml write race in spec_helper Every parallel_spec worker's before(:all) hook rewrote the shared spec/fixtures/hieradata/hiera.yaml in place; a catalogue compile in another worker during the truncation window saw an empty hiera config and silently dropped all custom hieradata, producing random hieradata-not-applied spec failures across the fleet. hiera.yaml is now written atomically (write + rename). See simp/puppetsync#90; validated on simp/pupmod-simp-simplib#363. --- spec/spec_helper.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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