forked from datanoise/amqp.cr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimed_channel_spec.cr
36 lines (32 loc) · 992 Bytes
/
timed_channel_spec.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require "spec"
require "../src/amqp/timed_channel"
describe "Timed::Channel" do
describe "TimerChannel" do
it "should periodically generate time values" do
timer = Timed::TimerChannel.new(10.milliseconds)
times = (1..2).map{ timer.receive }
times.size.should eq(2)
(times.last - times.first).should be >= 10.milliseconds
end
it "should raise exception on send" do
timer = Timed::TimerChannel.new(10.milliseconds)
expect_raises(Exception) do
timer.send Time.now
end
end
it "should not time out" do
ch = Timed::TimedChannel(Bool).new(1)
spawn { sleep(0.007); ch.send(true) }
if ch.receive(10.milliseconds).nil?
fail "channel should not time out"
end
end
it "should time out" do
ch = Timed:: TimedChannel(Bool).new(1)
spawn { sleep(0.1); ch.send(true) }
unless ch.receive(10.milliseconds).nil?
fail "channel should time out"
end
end
end
end