Skip to content

Commit

Permalink
test: rework box/on_shutdown test
Browse files Browse the repository at this point in the history
The test is flaky under high load (e.g. when is run in parallel with a
lot of workers). Make it less dependent on arbitrary timeouts to improve
stability.

Part of #4134

(cherry picked from commit c026052)
  • Loading branch information
sergepetrenko authored and locker committed Apr 12, 2019
1 parent 773462c commit 1111575
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
22 changes: 9 additions & 13 deletions test/box/on_shutdown.result
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ box.space.shutdown:select{}
box.space.shutdown:drop()
---
...
-- Check that os.exit invokes triggers
-- Check that os.exit invokes on_shutdown triggers
fiber = require("fiber")
---
...
Expand Down Expand Up @@ -116,13 +116,17 @@ _ = box.ctl.on_shutdown(function() print("on_shutdown 5") end)
fiber = require("fiber")
---
...
_ = fiber.create(function() fiber.sleep(0.05) os.exit() while true do end end)
---
...
test_run:cmd("switch default")
---
- true
...
-- eval the command on the 'test' instance while we're on default
-- instance to make sure test_run doesn't lose connection to the
-- shutting down instance.
test_run:eval("test", "_ = fiber.new(function() os.exit() while true do end end)")
---
- []
...
fiber.sleep(0.1)
---
...
Expand All @@ -136,11 +140,7 @@ test_run:cmd("start server test")
---
- true
...
test_run:cmd("switch test")
---
- true
...
test_run:grep_log('test', 'on_shutdown 5', nil, {noreset=true})
test_run:wait_log('test', 'on_shutdown 5', nil, 30, {noreset=true})
---
- on_shutdown 5
...
Expand All @@ -149,10 +149,6 @@ test_run:grep_log('test', 'signal', nil, {noreset=true})
---
- null
...
test_run:cmd("switch default")
---
- true
...
test_run:cmd("stop server test")
---
- true
Expand Down
11 changes: 6 additions & 5 deletions test/box/on_shutdown.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_run:grep_log('default', 'on_shutdown 4', nil, {noreset=true})
box.space.shutdown:select{}
box.space.shutdown:drop()

-- Check that os.exit invokes triggers
-- Check that os.exit invokes on_shutdown triggers
fiber = require("fiber")
test_run:cmd("create server test with script='box/proxy.lua'")
test_run:cmd("start server test")
Expand All @@ -47,18 +47,19 @@ _ = 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")
_ = fiber.create(function() fiber.sleep(0.05) os.exit() while true do end end)
test_run:cmd("switch default")
-- eval the command on the 'test' instance while we're on default
-- instance to make sure test_run doesn't lose connection to the
-- shutting down instance.
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")
test_run:cmd("start server test")
test_run:cmd("switch test")
test_run:grep_log('test', 'on_shutdown 5', nil, {noreset=true})
test_run:wait_log('test', 'on_shutdown 5', nil, 30, {noreset=true})
-- make sure we exited because of os.exit(), not a signal.
test_run:grep_log('test', 'signal', nil, {noreset=true})
test_run:cmd("switch default")
test_run:cmd("stop server test")
test_run:cmd("cleanup server test")
test_run:cmd("delete server test")

0 comments on commit 1111575

Please sign in to comment.