diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index c18f6f0c..1a48aa6f 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -11,28 +11,42 @@ env: jobs: test: - name: ${{matrix.ruby}} on ${{matrix.os}} + name: ${{matrix.ruby}} on ${{matrix.os}} with ${{matrix.selector}} runs-on: ${{matrix.os}}-latest strategy: matrix: - os: - - ubuntu - - ruby: - - "3.1" - - "3.2" - - "ruby-head" - + include: + - os: ubuntu + ruby: "3.1" + selector: EPoll + - os: ubuntu + ruby: "3.2" + selector: EPoll + - os: ubuntu + ruby: "3.3" + selector: EPoll + - os: ubuntu + ruby: "3.3" + selector: URing + steps: - uses: actions/checkout@v3 + + - name: Install packages (Ubuntu) + if: matrix.os == 'ubuntu' + run: sudo apt-get install -y liburing-dev + - uses: ruby/setup-ruby@v1 with: ruby-version: ${{matrix.ruby}} bundler-cache: true + cache-version: io_uring - name: Run tests timeout-minutes: 5 + env: + IO_EVENT_SELECTOR: ${{matrix.selector}} run: bundle exec bake test - uses: actions/upload-artifact@v2 diff --git a/.github/workflows/test-io_uring.yaml b/.github/workflows/test-io_uring.yaml new file mode 100644 index 00000000..7595eda1 --- /dev/null +++ b/.github/workflows/test-io_uring.yaml @@ -0,0 +1,47 @@ +name: Test + +on: [push, pull_request] + +permissions: + contents: read + +env: + CONSOLE_OUTPUT: XTerm + IO_EVENT_SELECTOR: URing + +jobs: + test: + name: ${{matrix.ruby}} on ${{matrix.os}} / IO_EVENT_SELECTOR=URing + runs-on: ${{matrix.os}}-latest + + strategy: + matrix: + os: + - ubuntu + + ruby: + - "3.3" + + steps: + - uses: actions/checkout@v3 + + - name: Install packages (Ubuntu) + if: matrix.os == 'ubuntu' + run: sudo apt-get install -y liburing-dev + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{matrix.ruby}} + bundler-cache: true + cache-version: io_uring + + - name: Backends + run: bundle exec ruby -r"io/event" -e "puts IO::Event::Selector.constants" + + - name: Run tests + timeout-minutes: 10 + run: bundle exec bake test + + # - name: Run external tests + # timeout-minutes: 10 + # run: bundle exec bake test:external diff --git a/lib/async/scheduler.rb b/lib/async/scheduler.rb index accf41e9..32445b2d 100644 --- a/lib/async/scheduler.rb +++ b/lib/async/scheduler.rb @@ -203,7 +203,7 @@ def io_read(io, buffer, length, offset = 0) if timeout = get_timeout(io) timer = @timers.after(timeout) do - fiber.raise(::IO::TimeoutError, "execution expired") + fiber.raise(::IO::TimeoutError, "Timeout while waiting for IO to become readable!") end end @@ -215,10 +215,10 @@ def io_read(io, buffer, length, offset = 0) if RUBY_ENGINE != "ruby" || RUBY_VERSION >= "3.3.0" def io_write(io, buffer, length, offset = 0) fiber = Fiber.current - + if timeout = get_timeout(io) timer = @timers.after(timeout) do - fiber.raise(::IO::TimeoutError, "execution expired") + fiber.raise(::IO::TimeoutError, "Timeout while waiting for IO to become writable!") end end diff --git a/test/io.rb b/test/io.rb index ce32a43c..880d9f46 100644 --- a/test/io.rb +++ b/test/io.rb @@ -42,6 +42,19 @@ end.to raise_exception(::IO::TimeoutError) end + it "can write with timeout" do + skip_unless_constant_defined(:TimeoutError, IO) + + input, output = IO.pipe + output.timeout = 0.001 + + expect do + while true + output.write("Hello") + end + end.to raise_exception(::IO::TimeoutError) + end + it "can wait readable with default timeout" do skip_unless_constant_defined(:TimeoutError, IO)