spec/hashed_wheel_spec.rb in zmachine-0.1.3 vs spec/hashed_wheel_spec.rb in zmachine-0.2.0
- old
+ new
@@ -1,15 +1,7 @@
-require 'spec_helper'
-require 'lib/zmachine/hashed_wheel'
+require 'zmachine/hashed_wheel'
-describe ZMachine::HashedWheelTimeout do
- it 'calculates the stop index correctly'
- it 'calculates remaining rounds correctly'
- it 'can be cancelled'
- it 'supports an action'
-end
-
describe ZMachine::HashedWheel do
let(:wheel) { ZMachine::HashedWheel.new(16, 100) }
it 'returns a timeout on add' do
expect(wheel.add(0)).to be_instance_of(ZMachine::HashedWheelTimeout)
@@ -33,17 +25,28 @@
wheel.add 50
timedout = wheel.advance(now + 30 * 1_000_000)
expect(timedout.length).to eq(1)
end
- it 'calculates the timeouted set correctly' do
+ it 'calculates the timeout set correctly' do
now = wheel.reset
wheel.add 10
wheel.add 40
wheel.add 1900
wheel.add 3300
wheel.add 4000
- timedout = wheel.advance( now + 3900 * 1_000_000)
+ timedout = wheel.advance(now + 3900 * 1_000_000)
expect(timedout).to be
expect(timedout.length).to eq(4)
end
-end
\ No newline at end of file
+
+ it 'cancels timers correctly' do
+ now = wheel.reset
+ t1 = wheel.add 90
+ t2 = wheel.add 110
+ t1.cancel
+ timedout = wheel.advance(now + 200 * 1_000_000)
+ expect(timedout).to eq([t2])
+ expect(timedout.length).to eq(1)
+ end
+
+end