diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bcf3dd..3a41eb0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,10 +6,10 @@ on: jobs: test: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: + os: [ ubuntu-latest, windows-latest ] ruby: - '2.2' - '2.3' @@ -20,6 +20,7 @@ jobs: - '3.0' - '3.1' - 'head' + runs-on: ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cc7953..72f9679 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## HEAD (unreleased) + - Improve message when Terminate on Timeout is used on a platform that does not support it (eg. Windows or JVM) ## 0.6.3 diff --git a/lib/rack/timeout/core.rb b/lib/rack/timeout/core.rb index 85a34a2..ae6247a 100644 --- a/lib/rack/timeout/core.rb +++ b/lib/rack/timeout/core.rb @@ -74,8 +74,14 @@ def initialize(app, service_timeout:nil, wait_timeout:nil, wait_overtime:nil, se @service_past_wait = service_past_wait == "not_specified" ? ENV.fetch("RACK_TIMEOUT_SERVICE_PAST_WAIT", false).to_s != "false" : service_past_wait Thread.main['RACK_TIMEOUT_COUNT'] ||= 0 - if @term_on_timeout - raise "Current Runtime does not support processes" unless ::Process.respond_to?(:fork) + if @term_on_timeout && !::Process.respond_to?(:fork) + raise(NotImplementedError, <<-MSG) +The platform running your application does not support forking (i.e. Windows, JVM, etc). + +To avoid this error, either specify RACK_TIMEOUT_TERM_ON_TIMEOUT=0 or +leave it as default (which will have the same result). + +MSG end @app = app end diff --git a/test/env_settings_test.rb b/test/env_settings_test.rb index 6b964ff..6592644 100644 --- a/test/env_settings_test.rb +++ b/test/env_settings_test.rb @@ -2,13 +2,6 @@ class EnvSettingsTest < RackTimeoutTest - def test_service_timeout - with_env(RACK_TIMEOUT_SERVICE_TIMEOUT: 1) do - assert_raises(Rack::Timeout::RequestTimeoutError) do - get "/sleep" - end - end - end def test_zero_wait_timeout with_env(RACK_TIMEOUT_WAIT_TIMEOUT: 0) do @@ -17,10 +10,29 @@ def test_zero_wait_timeout end end - def test_term - with_env(RACK_TIMEOUT_TERM_ON_TIMEOUT: 1) do - assert_raises(SignalException) do - get "/sleep" + + if Process.respond_to?(:fork) # This functionality does not work on windows, so we cannot test it there. + def test_service_timeout + with_env(RACK_TIMEOUT_SERVICE_TIMEOUT: 1) do + assert_raises(Rack::Timeout::RequestTimeoutError) do + get "/sleep" + end + end + end + + def test_term + with_env(RACK_TIMEOUT_TERM_ON_TIMEOUT: 1) do + assert_raises(SignalException) do + get "/sleep" + end + end + end + else + def test_service_timeout # Confirm that on Windows we raise an exception when someone attempts to use term on timeout + with_env(RACK_TIMEOUT_TERM_ON_TIMEOUT: 1) do + assert_raises(NotImplementedError) do + get "/" + end end end end