Skip to content

Commit e2b80a5

Browse files
LeonidVasTotktonada
authored andcommitted
test: add a test for release all tasks on start
Follow-up #66 Follow-up #121
1 parent b87cd7d commit e2b80a5

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

t/130-release-all-tasks-on-start.t

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env tarantool
2+
3+
local os = require('os')
4+
local queue = require('queue')
5+
local tap = require('tap')
6+
local tnt = require('t.tnt')
7+
8+
local test = tap.test('release all tasks on start')
9+
test:plan(1)
10+
11+
---
12+
-- Accept gh-66, we need to release all taken tasks on start.
13+
-- Instead of tarantool reboot, we will additionally call queue.start()
14+
-- to simulate the reload of the module. This is not a clean enough,
15+
-- because fibers launched by the module are not cleaned up.
16+
-- See https://github.com/tarantool/queue/issues/66
17+
--
18+
-- All tricks in this test are done by professionals, don't try
19+
-- to repeat it yourself!!!
20+
local function check_release_tasks_on_start()
21+
tnt.cfg()
22+
-- The "fifottl" driver was choosen for check gh-121.
23+
-- We cann't use opts == nil as argument for driver "release"
24+
-- method. This is the policy of the module "queue" (check
25+
-- opts in abstract.lua, instead to check inside the driver).
26+
-- See https://github.com/tarantool/queue/issues/121
27+
local driver = 'fifottl'
28+
local tube = queue.create_tube('test_tube', driver)
29+
30+
tube:put('1')
31+
tube:put('2')
32+
tube:put('3')
33+
34+
tube:take()
35+
tube:take()
36+
tube:take()
37+
38+
-- Simulate the module reload.
39+
queue.start()
40+
41+
local ready_tasks_num = queue.statistics()['test_tube']['tasks']['ready']
42+
test:is(ready_tasks_num, 3, 'check release tasks on start')
43+
end
44+
45+
check_release_tasks_on_start()
46+
47+
tnt.finish()
48+
os.exit(test:check() and 0 or 1)

0 commit comments

Comments
 (0)