Skip to content

Commit 0ed9bef

Browse files
authored
Add write timeout test. (#298)
* Add `io_uring` to coverage test workflow.
1 parent 2fcb2ca commit 0ed9bef

File tree

4 files changed

+86
-12
lines changed

4 files changed

+86
-12
lines changed

.github/workflows/coverage.yaml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,42 @@ env:
1111

1212
jobs:
1313
test:
14-
name: ${{matrix.ruby}} on ${{matrix.os}}
14+
name: ${{matrix.ruby}} on ${{matrix.os}} with ${{matrix.selector}}
1515
runs-on: ${{matrix.os}}-latest
1616

1717
strategy:
1818
matrix:
19-
os:
20-
- ubuntu
21-
22-
ruby:
23-
- "3.1"
24-
- "3.2"
25-
- "ruby-head"
26-
19+
include:
20+
- os: ubuntu
21+
ruby: "3.1"
22+
selector: EPoll
23+
- os: ubuntu
24+
ruby: "3.2"
25+
selector: EPoll
26+
- os: ubuntu
27+
ruby: "3.3"
28+
selector: EPoll
29+
- os: ubuntu
30+
ruby: "3.3"
31+
selector: URing
32+
2733
steps:
2834
- uses: actions/checkout@v3
35+
36+
- name: Install packages (Ubuntu)
37+
if: matrix.os == 'ubuntu'
38+
run: sudo apt-get install -y liburing-dev
39+
2940
- uses: ruby/setup-ruby@v1
3041
with:
3142
ruby-version: ${{matrix.ruby}}
3243
bundler-cache: true
44+
cache-version: io_uring
3345

3446
- name: Run tests
3547
timeout-minutes: 5
48+
env:
49+
IO_EVENT_SELECTOR: ${{matrix.selector}}
3650
run: bundle exec bake test
3751

3852
- uses: actions/upload-artifact@v2
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Test
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
env:
9+
CONSOLE_OUTPUT: XTerm
10+
IO_EVENT_SELECTOR: URing
11+
12+
jobs:
13+
test:
14+
name: ${{matrix.ruby}} on ${{matrix.os}} / IO_EVENT_SELECTOR=URing
15+
runs-on: ${{matrix.os}}-latest
16+
17+
strategy:
18+
matrix:
19+
os:
20+
- ubuntu
21+
22+
ruby:
23+
- "3.3"
24+
25+
steps:
26+
- uses: actions/checkout@v3
27+
28+
- name: Install packages (Ubuntu)
29+
if: matrix.os == 'ubuntu'
30+
run: sudo apt-get install -y liburing-dev
31+
32+
- uses: ruby/setup-ruby@v1
33+
with:
34+
ruby-version: ${{matrix.ruby}}
35+
bundler-cache: true
36+
cache-version: io_uring
37+
38+
- name: Backends
39+
run: bundle exec ruby -r"io/event" -e "puts IO::Event::Selector.constants"
40+
41+
- name: Run tests
42+
timeout-minutes: 10
43+
run: bundle exec bake test
44+
45+
# - name: Run external tests
46+
# timeout-minutes: 10
47+
# run: bundle exec bake test:external

lib/async/scheduler.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def io_read(io, buffer, length, offset = 0)
203203

204204
if timeout = get_timeout(io)
205205
timer = @timers.after(timeout) do
206-
fiber.raise(::IO::TimeoutError, "execution expired")
206+
fiber.raise(::IO::TimeoutError, "Timeout while waiting for IO to become readable!")
207207
end
208208
end
209209

@@ -215,10 +215,10 @@ def io_read(io, buffer, length, offset = 0)
215215
if RUBY_ENGINE != "ruby" || RUBY_VERSION >= "3.3.0"
216216
def io_write(io, buffer, length, offset = 0)
217217
fiber = Fiber.current
218-
218+
219219
if timeout = get_timeout(io)
220220
timer = @timers.after(timeout) do
221-
fiber.raise(::IO::TimeoutError, "execution expired")
221+
fiber.raise(::IO::TimeoutError, "Timeout while waiting for IO to become writable!")
222222
end
223223
end
224224

test/io.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@
4242
end.to raise_exception(::IO::TimeoutError)
4343
end
4444

45+
it "can write with timeout" do
46+
skip_unless_constant_defined(:TimeoutError, IO)
47+
48+
input, output = IO.pipe
49+
output.timeout = 0.001
50+
51+
expect do
52+
while true
53+
output.write("Hello")
54+
end
55+
end.to raise_exception(::IO::TimeoutError)
56+
end
57+
4558
it "can wait readable with default timeout" do
4659
skip_unless_constant_defined(:TimeoutError, IO)
4760

0 commit comments

Comments
 (0)