Skip to content

Commit fe8aa06

Browse files
committed
More improvements to test, fixes #218.
1 parent 8f59041 commit fe8aa06

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

spec/async/scheduler_spec.rb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,19 @@
5656
let(:message) {"Helloooooo World!"}
5757

5858
it "can send message via pipe" do
59-
input, output = IO.pipe
60-
61-
reactor.async do
62-
sleep(0.001)
63-
64-
message.each_char do |character|
65-
output.write(character)
59+
IO.pipe do |input, output|
60+
reactor.async do
61+
sleep(0.001)
62+
63+
message.each_char do |character|
64+
output.write(character)
65+
end
66+
67+
output.close
6668
end
6769

68-
output.close
70+
expect(input.read).to be == message
6971
end
70-
71-
expect(input.read).to be == message
72-
73-
input.close
7472
end
7573

7674
it "can fetch website using Net::HTTP" do

spec/async/task_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,13 @@
300300
it "can sleep for the requested duration" do
301301
state = nil
302302

303-
reactor.async do |task|
304-
task.sleep(duration)
305-
state = :finished
306-
end
307-
303+
# Measure the entire time, it's got to be at least bigger than the requested duration:
308304
time = Async::Clock.measure do
305+
reactor.async do |task|
306+
task.sleep(duration)
307+
state = :finished
308+
end
309+
309310
reactor.run
310311
end
311312

0 commit comments

Comments
 (0)