From f9da6e336626a62a410ae9a739b7a6ecc3d5b6ab Mon Sep 17 00:00:00 2001 From: Benjamin Wood Date: Sat, 13 Jan 2024 20:48:33 +0000 Subject: [PATCH] Fix flakey specs Co-authored-by: Nate Vick --- lib/selective/ruby/core/file_correlator.rb | 5 ++++- spec/selective/ruby/core/controller_spec.rb | 1 + spec/selective/ruby/core/file_correlator_spec.rb | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/selective/ruby/core/file_correlator.rb b/lib/selective/ruby/core/file_correlator.rb index b964659..1d71a4d 100644 --- a/lib/selective/ruby/core/file_correlator.rb +++ b/lib/selective/ruby/core/file_correlator.rb @@ -17,7 +17,10 @@ def initialize(diff, num_commits, target_branch) def correlate JSON.parse(get_correlated_files, symbolize_names: true) rescue FileCorrelatorError, JSON::ParserError - print_warning "Selective was unable to correlate the diff to test files. This may result in a sub-optimal test order. If the issue persists, please contact support." + print_warning(<<~MSG) + Selective was unable to correlate the diff to test files. This may result in a sub-optimal test order. + If the issue persists, please contact support. + MSG end private diff --git a/spec/selective/ruby/core/controller_spec.rb b/spec/selective/ruby/core/controller_spec.rb index 9d5f950..861e495 100644 --- a/spec/selective/ruby/core/controller_spec.rb +++ b/spec/selective/ruby/core/controller_spec.rb @@ -9,6 +9,7 @@ before do allow(Process).to receive(:spawn).and_return(123) + allow(controller).to receive(:kill_transport) allow(controller).to receive(:handle_termination_signals) allow(controller).to receive(:wait_for_connectivity) allow(controller).to receive(:exit) diff --git a/spec/selective/ruby/core/file_correlator_spec.rb b/spec/selective/ruby/core/file_correlator_spec.rb index f59b924..9c3d52b 100644 --- a/spec/selective/ruby/core/file_correlator_spec.rb +++ b/spec/selective/ruby/core/file_correlator_spec.rb @@ -4,6 +4,11 @@ describe "#correlate" do it "returns a hash with the expected shape" do + # The fetch normally happens when the diff is generated + # but if another runner created the manifest the fetch may + # not have happened on the runner that is running this test. + # So, we fetch here to ensure this test ddoes not fail. + `git fetch origin #{target_branch} --depth=1` expect(instance.correlate).to match({:correlated_files => Hash, :uncorrelated_files => Hash}) end