-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: rework box/misc test part regarding on_shutdown triggers
Rewrite the test so that it doesn't depend on timeouts, which can be exceeded under high load, too much and simplify it a little. Also extract the whole part regarding on_shutdown triggers into a separate test, so that its sporadic failures would be easier to investigate. Part of #4134
- Loading branch information
1 parent
319ab0a
commit 70b5c7c
Showing
4 changed files
with
222 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
env = require('test_run') | ||
--- | ||
... | ||
test_run = env.new() | ||
--- | ||
... | ||
-- | ||
-- gh-1607: on_shutdown triggers. | ||
-- | ||
f = function() print('on_shutdown 1') end | ||
--- | ||
... | ||
g = function() print('on_shutdown 2') end | ||
--- | ||
... | ||
h = function() print('on_shutdown 3') end | ||
--- | ||
... | ||
-- Check that on_shutdown triggers may yield | ||
-- and perform some complicated actions. | ||
fiber = require('fiber') | ||
--- | ||
... | ||
test_run:cmd("setopt delimiter ';'") | ||
--- | ||
- true | ||
... | ||
trig = function() | ||
fiber.sleep(0.01) | ||
fiber.yield() | ||
box.schema.space.create("shutdown") | ||
box.space.shutdown:create_index("pk") | ||
box.space.shutdown:insert{1,2,3} | ||
print('on_shutdown 4') | ||
end; | ||
--- | ||
... | ||
test_run:cmd("setopt delimiter ''"); | ||
--- | ||
- true | ||
... | ||
_ = box.ctl.on_shutdown(f) | ||
--- | ||
... | ||
_ = box.ctl.on_shutdown(g) | ||
--- | ||
... | ||
-- Check that replacing triggers works | ||
_ = box.ctl.on_shutdown(h, g) | ||
--- | ||
... | ||
_ = box.ctl.on_shutdown(trig) | ||
--- | ||
... | ||
test_run:cmd('restart server default') | ||
test_run:grep_log('default', 'on_shutdown 1', nil, {noreset=true}) | ||
--- | ||
- on_shutdown 1 | ||
... | ||
test_run:grep_log('default', 'on_shutdown 2', nil, {noreset=true}) | ||
--- | ||
- null | ||
... | ||
test_run:grep_log('default', 'on_shutdown 3', nil, {noreset=true}) | ||
--- | ||
- on_shutdown 3 | ||
... | ||
test_run:grep_log('default', 'on_shutdown 4', nil, {noreset=true}) | ||
--- | ||
- on_shutdown 4 | ||
... | ||
box.space.shutdown:select{} | ||
--- | ||
- - [1, 2, 3] | ||
... | ||
box.space.shutdown:drop() | ||
--- | ||
... | ||
-- Check that os.exit invokes on_shutdown triggers | ||
fiber = require("fiber") | ||
--- | ||
... | ||
test_run:cmd("create server test with script='box/proxy.lua'") | ||
--- | ||
- true | ||
... | ||
test_run:cmd("start server test") | ||
--- | ||
- true | ||
... | ||
logfile = test_run:eval("test", "box.cfg.log")[1] | ||
--- | ||
... | ||
test_run:cmd("stop server test") | ||
--- | ||
- true | ||
... | ||
-- clean up any leftover logs | ||
require("fio").unlink(logfile) | ||
--- | ||
- true | ||
... | ||
test_run:cmd("start server test") | ||
--- | ||
- true | ||
... | ||
test_run:cmd("switch test") | ||
--- | ||
- true | ||
... | ||
_ = box.ctl.on_shutdown(function() print("on_shutdown 5") end) | ||
--- | ||
... | ||
-- Check that we don't hang infinitely after os.exit() | ||
-- even if the following code doesn't yield. | ||
fiber = require('fiber') | ||
--- | ||
... | ||
test_run:cmd("switch default") | ||
--- | ||
- true | ||
... | ||
test_run:eval("test", "_ = fiber.new(function() os.exit() while true do end end)") | ||
--- | ||
- [] | ||
... | ||
fiber.sleep(0.1) | ||
--- | ||
... | ||
-- The server should be already stopped by os.exit(), | ||
-- but start doesn't work without a prior call to stop. | ||
test_run:cmd("stop server test") | ||
--- | ||
- true | ||
... | ||
test_run:cmd("start server test") | ||
--- | ||
- true | ||
... | ||
test_run:wait_log('test', 'on_shutdown 5', nil, 5, {noreset=true}) | ||
--- | ||
- on_shutdown 5 | ||
... | ||
-- make sure we exited because of os.exit(), not a signal. | ||
test_run:grep_log('test', 'signal', nil, {noreset=true}) | ||
--- | ||
- null | ||
... | ||
test_run:cmd("stop server test") | ||
--- | ||
- true | ||
... | ||
test_run:cmd("cleanup server test") | ||
--- | ||
- true | ||
... | ||
test_run:cmd("delete server test") | ||
--- | ||
- true | ||
... |
Oops, something went wrong.