Skip to content

Commit a7d66a1

Browse files
committed
Move expectations (that can perform IO#write) out of non-blocking fibers.
1 parent 9722020 commit a7d66a1

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

test/async/task.rb

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@
7575

7676
with "#current?" do
7777
it "can check if it is the currently running task" do
78+
was_current = nil
79+
7880
task = reactor.async do |task|
79-
expect(task).to be(:current?)
80-
sleep(0.1)
81+
was_current = task.current?
8182
end
8283

84+
expect(was_current).to be == true
8385
expect(task).not.to be(:current?)
8486
end
8587
end
@@ -124,7 +126,8 @@
124126
reactor.run do
125127
expect do
126128
reactor.async do |task|
127-
expect(task).to receive(:warn).and_return(nil)
129+
# Ensure the wait is executed before raising the exception:
130+
task.yield
128131

129132
raise "boom"
130133
end.wait
@@ -154,19 +157,19 @@
154157
it "can consume exceptions" do
155158
task = nil
156159

157-
expect do
158-
task = reactor.async do |task|
159-
expect(task).to receive(:warn).and_return(nil)
160-
161-
raise "boom"
162-
end
163-
end.not.to raise_exception
164-
165160
reactor.run do
166161
expect do
167-
task.wait
168-
end.to raise_exception(RuntimeError, message: be =~ /boom/)
162+
task = reactor.async do |task|
163+
expect(task).to receive(:warn).and_return(nil)
164+
165+
raise "boom"
166+
end
167+
end.not.to raise_exception
169168
end
169+
170+
expect do
171+
task.wait
172+
end.to raise_exception(RuntimeError, message: be =~ /boom/)
170173
end
171174

172175
it "won't consume non-StandardError exceptions" do
@@ -508,6 +511,7 @@
508511

509512
it "can stop resumed task" do
510513
items = [1, 2, 3]
514+
value = nil
511515

512516
reactor.run do
513517
condition = Async::Condition.new
@@ -520,11 +524,11 @@
520524
end
521525

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

527530
expect(items).to be == [1, 2]
531+
expect(value).to be == 3
528532
end
529533

530534
it "can stop a child task with transient children" do
@@ -720,7 +724,7 @@ def sleep_forever
720724
end
721725

722726
innocent_task = reactor.async do |task|
723-
expect{error_task.wait}.to raise_exception(RuntimeError, message: be =~ /boom/)
727+
error_task.wait
724728
end
725729

726730
expect do
@@ -729,6 +733,10 @@ def sleep_forever
729733

730734
expect(error_task).to be(:finished?)
731735
expect(innocent_task).to be(:finished?)
736+
737+
expect do
738+
innocent_task.wait
739+
end.to raise_exception(RuntimeError, message: be =~ /boom/)
732740
end
733741

734742
it "will not raise exception values returned by the task" do

0 commit comments

Comments
 (0)