Tarantool development patches archive
 help / color / mirror / Atom feed
From: Serge Petrenko <sergepetrenko@tarantool.org>
To: vdavydov.dev@gmail.com
Cc: tarantool-patches@freelists.org,
	Serge Petrenko <sergepetrenko@tarantool.org>
Subject: [PATCH] test: rework box/misc test part regarding on_shutdown triggers
Date: Thu, 11 Apr 2019 16:37:20 +0300	[thread overview]
Message-ID: <20190411133720.39993-1-sergepetrenko@tarantool.org> (raw)

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
---
https://github.com/tarantool/tarantool/issues/4134
https://github.com/tarantool/tarantool/tree/sp/gh-4134-fix-on-shutdown-tests

 test/box/misc.result                   | 161 -------------------------
 test/box/misc.test.lua                 |  62 ----------
 test/box/on_shutdown_triggers.result   | 160 ++++++++++++++++++++++++
 test/box/on_shutdown_triggers.test.lua |  62 ++++++++++
 4 files changed, 222 insertions(+), 223 deletions(-)
 create mode 100644 test/box/on_shutdown_triggers.result
 create mode 100644 test/box/on_shutdown_triggers.test.lua

diff --git a/test/box/misc.result b/test/box/misc.result
index e2b618c9c..a1f7a0990 100644
--- a/test/box/misc.result
+++ b/test/box/misc.result
@@ -1269,164 +1269,3 @@ box.cfg{too_long_threshold = too_long_threshold}
 s:drop()
 ---
 ...
---
--- 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 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")
----
-...
-_ = fiber.create(function() fiber.sleep(0.05) os.exit() while true do end end)
----
-...
-test_run:cmd("switch default")
----
-- true
-...
-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:cmd("switch test")
----
-- true
-...
-test_run:grep_log('test', 'on_shutdown 5', nil, {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("switch default")
----
-- true
-...
-test_run:cmd("stop server test")
----
-- true
-...
-test_run:cmd("cleanup server test")
----
-- true
-...
-test_run:cmd("delete server test")
----
-- true
-...
diff --git a/test/box/misc.test.lua b/test/box/misc.test.lua
index 18128b299..cc6cb34fb 100644
--- a/test/box/misc.test.lua
+++ b/test/box/misc.test.lua
@@ -352,65 +352,3 @@ rows == expected_rows
 lsn == expected_lsn
 box.cfg{too_long_threshold = too_long_threshold}
 s:drop()
-
---
--- 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 ';'")
-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 ''");
-_ = 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})
-test_run:grep_log('default', 'on_shutdown 2', nil, {noreset=true})
-test_run:grep_log('default', 'on_shutdown 3', nil, {noreset=true})
-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
-fiber = require("fiber")
-test_run:cmd("create server test with script='box/proxy.lua'")
-test_run:cmd("start server test")
-logfile = test_run:eval("test", "box.cfg.log")[1]
-test_run:cmd("stop server test")
--- clean up any leftover logs
-require("fio").unlink(logfile)
-test_run:cmd("start server test")
-test_run:cmd("switch test")
-_ = 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")
-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})
--- 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")
diff --git a/test/box/on_shutdown_triggers.result b/test/box/on_shutdown_triggers.result
new file mode 100644
index 000000000..da45f63a6
--- /dev/null
+++ b/test/box/on_shutdown_triggers.result
@@ -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
+...
diff --git a/test/box/on_shutdown_triggers.test.lua b/test/box/on_shutdown_triggers.test.lua
new file mode 100644
index 000000000..9f8b0ae64
--- /dev/null
+++ b/test/box/on_shutdown_triggers.test.lua
@@ -0,0 +1,62 @@
+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 ';'")
+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 ''");
+_ = 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})
+test_run:grep_log('default', 'on_shutdown 2', nil, {noreset=true})
+test_run:grep_log('default', 'on_shutdown 3', nil, {noreset=true})
+test_run:grep_log('default', 'on_shutdown 4', nil, {noreset=true})
+box.space.shutdown:select{}
+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'")
+test_run:cmd("start server test")
+logfile = test_run:eval("test", "box.cfg.log")[1]
+test_run:cmd("stop server test")
+-- clean up any leftover logs
+require("fio").unlink(logfile)
+test_run:cmd("start server test")
+test_run:cmd("switch test")
+_ = 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")
+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:wait_log('test', 'on_shutdown 5', nil, 5, {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("stop server test")
+test_run:cmd("cleanup server test")
+test_run:cmd("delete server test")
-- 
2.20.1 (Apple Git-117)

             reply	other threads:[~2019-04-11 13:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11 13:37 Serge Petrenko [this message]
2019-04-12 14:00 ` Vladimir Davydov
2019-04-12 14:12   ` [tarantool-patches] " Serge Petrenko
2019-04-12 14:20     ` Vladimir Davydov
2019-04-12 14:35       ` Serge Petrenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190411133720.39993-1-sergepetrenko@tarantool.org \
    --to=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH] test: rework box/misc test part regarding on_shutdown triggers' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox