diff --git a/features/support/env.rb b/features/support/env.rb index 1428a0b..3a7fcfc 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -27,3 +27,7 @@ end Around '@other_wm_running' do |_, block| with_other_wm { block.call } end + +if ENV.key? 'TRAVIS' + ENV['UHWMTEST_TIMEOUT'] = 8.to_s +end diff --git a/lib/uh/wm/testing/acceptance_helpers.rb b/lib/uh/wm/testing/acceptance_helpers.rb index f157cf3..bf5d05b 100644 --- a/lib/uh/wm/testing/acceptance_helpers.rb +++ b/lib/uh/wm/testing/acceptance_helpers.rb @@ -22,23 +22,18 @@ module Uh @process.stdout end - def uhwm_wait_output message, timeout: 1 - Timeout.timeout(timeout) do - loop do - break if case message - when Regexp then @process.stdout + @process.stderr =~ message - when String then assert_partial_output_interactive message - end - sleep 0.1 + def uhwm_wait_output message + output = -> { @process.stdout + @process.stderr } + timeout_until do + case message + when Regexp then output.call =~ message + when String then assert_partial_output_interactive message end end - rescue Timeout::Error - output = (@process.stdout + @process.stderr).lines - .map { |e| " #{e}" } - .join + rescue TimeoutError => e fail [ - "expected `#{message}' not seen after #{timeout} seconds in:", - " ```\n#{output} ```" + "expected `#{message}' not seen after #{e.timeout} seconds in:", + " ```\n#{output.call.lines.map { |e| " #{e}" }.join} ```" ].join "\n" end @@ -90,6 +85,30 @@ module Uh private + def timeout_until + timeout = ENV.key?('UHWMTEST_TIMEOUT') ? + ENV['UHWMTEST_TIMEOUT'].to_i : + 1 + Timeout.timeout(timeout) do + loop do + break if yield + sleep 0.1 + end + end + rescue Timeout::Error + fail TimeoutError.new('execution expired', timeout) + end + + + class TimeoutError < ::StandardError + attr_reader :timeout + + def initialize message, timeout + super message + @timeout = timeout + end + end + class XClient attr_reader :name