Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

- name: Run tests
timeout-minutes: 5
run: bundle exec bake test
run: bundle exec sus --verbose

- uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion async.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "console", "~> 1.29"
spec.add_dependency "fiber-annotation"
spec.add_dependency "io-event", "~> 1.11"
spec.add_dependency "io-event", "~> 1.12"
spec.add_dependency "metrics", "~> 0.12"
spec.add_dependency "traces", "~> 0.15"
end
4 changes: 1 addition & 3 deletions lib/async/limited_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

module Async
class LimitedQueue < Queue
class << self
remove_method :new
end
singleton_class.remove_method(:new)
end
end
1 change: 1 addition & 0 deletions lib/async/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def wait
# A queue which limits the number of items that can be enqueued.
# @public Since *Async v1*.
class LimitedQueue < Queue
# @private This exists purely for emitting a warning.
def self.new(...)
warn("`require 'async/limited_queue'` to use `Async::LimitedQueue`.", uplevel: 1, category: :deprecated) if $VERBOSE

Expand Down
2 changes: 1 addition & 1 deletion lib/async/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def to_s

# @deprecated Prefer {Kernel#sleep} except when compatibility with `stable-v1` is required.
def sleep(duration = nil)
warn("`Async::Task#sleep` is deprecated, use `Kernel#sleep` instead.", uplevel: 1, category: :deprecated) if $VERBOSE
Kernel.warn("`Async::Task#sleep` is deprecated, use `Kernel#sleep` instead.", uplevel: 1, category: :deprecated) if $VERBOSE

super
end
Expand Down
13 changes: 3 additions & 10 deletions test/async/barrier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,22 @@

with "#async" do
let(:repeats) {40}
let(:delay) {0.01}

it "should wait for all jobs to complete" do
finished = 0

repeats.times.map do |i|
barrier.async do |task|
sleep(delay)
task.yield
finished += 1

# This task is a child task but not part of the barrier.
task.async do
sleep(delay*3)
end
end
end

expect(barrier).not.to be(:empty?)
expect(finished).to be < repeats
expect(finished).to be <= repeats

duration = Async::Clock.measure{barrier.wait}
barrier.wait

expect(duration).to be_within(repeats * Sus::Fixtures::Time::QUANTUM).of(delay)
expect(finished).to be == repeats
expect(barrier).to be(:empty?)
end
Expand Down
13 changes: 6 additions & 7 deletions test/async/limited_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,16 @@ def before
with "#close" do
it "signals tasks waiting to enqueue items when closed" do
queue.enqueue(:item1)

# This task will block as the queue is full:
waiting_task = reactor.async do
queue.enqueue(:item2)
expect do
queue.enqueue(:item2)
end.to raise_exception(Async::Queue::ClosedError)
end

queue.close

expect do
waiting_task.wait
end.to raise_exception(Async::Queue::ClosedError)
waiting_task.wait
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions test/async/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

expect(task.status).to be == :running

sequence << :yielding
reactor.yield
sequence << :finished

Expand All @@ -41,7 +40,6 @@
:waiting,
:running,
:signalled,
:yielding,
:resumed,
:finished
]
Expand Down
38 changes: 23 additions & 15 deletions test/async/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@

with "#current?" do
it "can check if it is the currently running task" do
was_current = nil

task = reactor.async do |task|
expect(task).to be(:current?)
sleep(0.1)
was_current = task.current?
end

expect(was_current).to be == true
expect(task).not.to be(:current?)
end
end
Expand Down Expand Up @@ -124,7 +126,8 @@
reactor.run do
expect do
reactor.async do |task|
expect(task).to receive(:warn).and_return(nil)
# Ensure the wait is executed before raising the exception:
task.yield

raise "boom"
end.wait
Expand Down Expand Up @@ -154,19 +157,19 @@
it "can consume exceptions" do
task = nil

expect do
task = reactor.async do |task|
expect(task).to receive(:warn).and_return(nil)

raise "boom"
end
end.not.to raise_exception

reactor.run do
expect do
task.wait
end.to raise_exception(RuntimeError, message: be =~ /boom/)
task = reactor.async do |task|
expect(task).to receive(:warn).and_return(nil)

raise "boom"
end
end.not.to raise_exception
end

expect do
task.wait
end.to raise_exception(RuntimeError, message: be =~ /boom/)
end

it "won't consume non-StandardError exceptions" do
Expand Down Expand Up @@ -508,6 +511,7 @@

it "can stop resumed task" do
items = [1, 2, 3]
value = nil

reactor.run do
condition = Async::Condition.new
Expand All @@ -520,11 +524,11 @@
end

value = condition.wait # (2) value = Fiber.yield
expect(value).to be == 3
producer.stop # (5) [producer is resumed already] producer.stop
end

expect(items).to be == [1, 2]
expect(value).to be == 3
end

it "can stop a child task with transient children" do
Expand Down Expand Up @@ -720,7 +724,7 @@ def sleep_forever
end

innocent_task = reactor.async do |task|
expect{error_task.wait}.to raise_exception(RuntimeError, message: be =~ /boom/)
error_task.wait
end

expect do
Expand All @@ -729,6 +733,10 @@ def sleep_forever

expect(error_task).to be(:finished?)
expect(innocent_task).to be(:finished?)

expect do
innocent_task.wait
end.to raise_exception(RuntimeError, message: be =~ /boom/)
end

it "will not raise exception values returned by the task" do
Expand Down
8 changes: 4 additions & 4 deletions test/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
read_task = Async do
expect do
r.read(5)
end.to raise_exception(IOError, message: be =~ /stream closed/)
end.to raise_exception(IOError, message: be =~ /closed/)
end

r.close
Expand All @@ -116,7 +116,7 @@
read_task = Async do
expect do
r.read(5)
end.to raise_exception(IOError, message: be =~ /stream closed/)
end.to raise_exception(IOError, message: be =~ /closed/)
end

close_task = Async do
Expand All @@ -135,7 +135,7 @@
read_task = Async do
expect do
r.read(5)
end.to raise_exception(IOError, message: be =~ /stream closed/)
end.to raise_exception(IOError, message: be =~ /closed/)
end

close_thread = Thread.new do
Expand All @@ -154,7 +154,7 @@
read_task = Async do
expect do
r.read(5)
end.to raise_exception(IOError, message: be =~ /stream closed/)
end.to raise_exception(IOError, message: be =~ /closed/)
end

close_thread = Thread.new do
Expand Down
Loading