From b1ec7f48bfc4528446ec10dc9ff5552050f1798e Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Fri, 2 Sep 2016 13:42:02 -0700 Subject: use threads to workaround Process.spawn buginess there's a WONTFIX closed bug in ruby-lang.org on this bug: https://bugs.ruby-lang.org/issues/10583 they seem to be favoring speed over accuracy with the result that if you're doing I/O synchronization (like our run_lock?) inside of a Process.spawn chain like this that you have to wrap the spawn calls inside of threads. probably a best practice to wrap every spawn call with a Thread. this probably also explains why we had the silly-long 20 second timeout? Signed-off-by: Lamont Granquist --- spec/integration/solo/solo_spec.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/spec/integration/solo/solo_spec.rb b/spec/integration/solo/solo_spec.rb index efbbde2af9..bfcb74b45c 100644 --- a/spec/integration/solo/solo_spec.rb +++ b/spec/integration/solo/solo_spec.rb @@ -133,16 +133,21 @@ EOM Timeout.timeout(120) do chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..") + threads = [] + # Instantiate the first chef-solo run - s1 = Process.spawn("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' \ --l debug -L #{path_to('logs/runs.log')}", :chdir => chef_dir) + threads << Thread.new do + s1 = Process.spawn("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' -l debug -L #{path_to('logs/runs.log')}", :chdir => chef_dir) + Process.waitpid(s1) + end # Instantiate the second chef-solo run - s2 = Process.spawn("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' \ --l debug -L #{path_to('logs/runs.log')}", :chdir => chef_dir) + threads << Thread.new do + s2 = Process.spawn("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' -l debug -L #{path_to('logs/runs.log')}", :chdir => chef_dir) + Process.waitpid(s2) + end - Process.waitpid(s1) - Process.waitpid(s2) + threads.each(&:join) end end.not_to raise_error -- cgit v1.2.1