File: timeout.rb

package info (click to toggle)
ruby-maxitest 6.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 468 kB
  • sloc: ruby: 1,587; makefile: 7
file content (34 lines) | stat: -rw-r--r-- 922 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# tests sometimes hang locally or on ci and with this we can actually debug the cause instead of just hanging forever
require 'timeout'

module Maxitest
  class << self
    attr_accessor :timeout
  end

  module Timeout
    class TestCaseTimeout < StandardError
      def message
        "Test took too long to finish, aborting. To use a debugger, def maxitest_timeout;false;end in the test file."
      end
    end

    def run(*, &block)
      # NOTE: having a default def maxitest_timeout would break using let(:maxitest_timeout)
      timeout = (defined?(maxitest_timeout) ? maxitest_timeout : Maxitest.timeout || 5)
      if timeout == false
        super
      else
        begin
          ::Timeout.timeout(timeout, TestCaseTimeout) { super }
        rescue TestCaseTimeout => e
          failures << UnexpectedError.new(e)
        end
      end
    end
  end
end

Minitest::Test.send :prepend, Maxitest::Timeout