From 4bc174cc628010daac0a9605f0e62363042583b0 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 22 Jul 2020 00:38:27 +0200 Subject: [PATCH] Add timeout for all specs. --- Library/Homebrew/test/spec_helper.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 337569b431..9e6ee3e826 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -29,6 +29,7 @@ require "rubocop" require "rubocop/rspec/support" require "find" require "byebug" +require "timeout" $LOAD_PATH.push(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/support/lib")) @@ -181,7 +182,19 @@ RSpec.configure do |config| $stderr.reopen(File::NULL) end - example.run + begin + timeout = example.metadata.fetch(:timeout, 60) + inner_timeout = nil + Timeout.timeout(timeout) do + example.run + rescue Timeout::Error => e + inner_timeout = e + end + rescue Timeout::Error + raise "Example exceeded maximum runtime of #{timeout} seconds." + end + + raise inner_timeout if inner_timeout rescue SystemExit => e raise "Unexpected exit with status #{e.status}." ensure