Comparison

spec/util_throttle_spec.lua @ 8236:4878e4159e12

Port tests to the `busted` test runner
author Waqas Hussain <waqas20@gmail.com>
date Fri, 15 Sep 2017 17:07:57 -0400
child 8245:9499db96c032
comparison
equal deleted inserted replaced
8235:7d9a2c200736 8236:4878e4159e12
1
2
3 -- Mock util.time
4 local now = 0; -- wibbly-wobbly... timey-wimey... stuff
5 local function later(n)
6 now = now + n; -- time passes at a different rate
7 end
8 package.loaded["util.time"] = {
9 now = function() return now; end
10 }
11
12
13 local throttle = require "util.throttle";
14
15 describe("util.sasl.scram", function()
16 describe("#Hi()", function()
17 it("should work", function()
18 local a = throttle.create(3, 10);
19
20 assert.are.equal(a:poll(1), true); -- 3 -> 2
21 assert.are.equal(a:poll(1), true); -- 2 -> 1
22 assert.are.equal(a:poll(1), true); -- 1 -> 0
23 assert.are.equal(a:poll(1), false); -- MEEP, out of credits!
24 later(1); -- ... what about
25 assert.are.equal(a:poll(1), false); -- now? - Still no!
26 later(9); -- Later that day
27 assert.are.equal(a:poll(1), true); -- Should be back at 3 credits ... 2
28 end);
29 end);
30 end);