Skip to content

Commit

Permalink
Add write timeout test. (#298)
Browse files Browse the repository at this point in the history
* Add `io_uring` to coverage test workflow.
  • Loading branch information
ioquatix authored Jan 3, 2024
1 parent 2fcb2ca commit 0ed9bef
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 12 deletions.
32 changes: 23 additions & 9 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/test-io_uring.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions lib/async/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
13 changes: 13 additions & 0 deletions test/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 0ed9bef

Please sign in to comment.