From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 03F752C2F9 for ; Fri, 12 Apr 2019 05:29:46 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 561YK3Zx99ms for ; Fri, 12 Apr 2019 05:29:45 -0400 (EDT) Received: from smtp55.i.mail.ru (smtp55.i.mail.ru [217.69.128.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 2BDAF2C2D1 for ; Fri, 12 Apr 2019 05:29:45 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() From: Roman Khabibov In-Reply-To: <20190411145725.il4veadyw4lcktj2@tkn_work_nb> Date: Fri, 12 Apr 2019 12:29:42 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <80D84297-4781-41C1-9E70-14712A77BA40@tarantool.org> References: <20190327134014.56676-1-roman.habibov@tarantool.org> <20190401054304.kofvdg3uz6fzwl5d@tkn_work_nb> <20190411145725.il4veadyw4lcktj2@tkn_work_nb> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: Alexander Turenko Hi! Thanks for the review. > On Apr 11, 2019, at 5:57 PM, Alexander Turenko = wrote: >=20 > The behaviour is almost okay, but you need to work on wording of the > commit message to make it useful for a reader. Feel free to ask more = if > you have questions. >=20 > See comments below. >=20 > WBR, Alexander Turenko. >=20 >> commit 4cdf8e79bb530288098fb30e5014498fc0ad4262 >> Author: Roman Khabibov >> Date: Mon Mar 25 20:52:05 2019 +0300 >>=20 >> tarantoolctl: error when box.cfg didn't called >=20 > Cite from our developer guidelines [1]: >=20 >> 6. Use the imperative mood in the subject line. A properly formed Git >> commit subject line should always be able to complete the following >> sentence: =E2=80=9CIf applied, this commit will /your subject line = here/=E2=80=9D. >=20 > [1]: = https://www.tarantool.io/en/doc/1.10/dev_guide/developer_guidelines/#how-t= o-write-a-commit-message >=20 > Also you construct passive voice wrongly, it should be 'to be + [not] = + Ved'. >=20 >>=20 >> There was assumpted uninitialized metamethods of box.cfg{} if user >> did't call it in his instance. >=20 > This sentence raises more questions then give answers. What is > 'uninitialized metamethods'? Whether 'of box.cfg{}' means result of = the > call or a new value of the 'cfg' field of the 'box' table? >=20 > Also I doubt 'There was assumpted' is valid phrase. tarantoolctl: raise error when box.cfg isn't called =20 There was no check whether box.cfg{} was initialized in an instance. If so, an error should be raised. >>=20 >> Closes #3953 >>=20 >> diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in >> index 47fcf895f..396fa7957 100755 >> --- a/extra/dist/tarantoolctl.in >> +++ b/extra/dist/tarantoolctl.in >> @@ -547,7 +547,11 @@ local function start() >> end >> os.exit(1) >> end >> - local old_call =3D getmetatable(box.cfg).__call >> + local m_table =3D getmetatable(box.cfg) >> + if m_table =3D=3D nil then >=20 > Cite from our Lua style guide [2]: >=20 >> `*_mt` and `*_methods` defines metatable and methods table >=20 > Suggested to name it box_cfg_mt. + local box_cfg_mt =3D getmetatable(box.cfg) > [2]: https://www.tarantool.io/en/doc/1.10/dev_guide/lua_style_guide/ >=20 >> + error("Plaese, call box.cfg{} within your instance") >=20 > Typo: 'Plaese'. >=20 > I would change wording to just state what is wrong, e.g.: 'box.cfg() = is > not called in an instance file'. >=20 > See also how errors are reported in other places: log.error() and > os.exit(1). I guess it does not matter much from a behaviour point of > view, but it would be good to report errors in one way with = surrounding > code. >=20 > (BTW, found one behaviour difference: error() reports a line number = when > called with one argument or non-zero second argument.) >=20 > Please, install tarantool and tarantoolctl and check the behaviour: > messages and exit codes. Currently it looks so: >=20 > # tarantoolctl start foo > Starting instance foo... > Hello, World! > /usr/bin/tarantoolctl:552: Plaese, call box.cfg{} within your instance > # echo $? > 1 >=20 > It is okay except file:line part, but anyway I suggest you to use > log.error() and os.exit(1). + if box_cfg_mt =3D=3D nil then + log.error('box.cfg() is not called in an instance file') + os.exit(1) >=20 >> if old_cfg.pid_file ~=3D nil and cfg ~=3D nil and = cfg.pid_file ~=3D nil then >> cfg.pid_file =3D old_cfg.pid_file >> diff --git a/test/app-tap/tarantoolctl.test.lua = b/test/app-tap/tarantoolctl.test.lua >> index db046e03f..428b074e2 100755 >> --- a/test/app-tap/tarantoolctl.test.lua >> +++ b/test/app-tap/tarantoolctl.test.lua >> @@ -165,10 +165,13 @@ do >> local dir =3D fio.tempdir() >> local code =3D [[ box.cfg{memtx_memory =3D 104857600} ]] >> create_script(dir, 'script.lua', code) >> + create_script(dir, 'init.lua', [[ print('Hi!') ]]) >>=20 >> local status, err =3D pcall(function() >> test:test("basic test", function(test_i) >> - test_i:plan(16) >> + test_i:plan(18) >> + check_ok(test_i, dir, 'start', 'init.lua', 1, nil, = "Starting instance init...", >> + "Plaese, call box.cfg{} within your instance") >> check_ok(test_i, dir, 'start', 'script', 0, nil, = "Starting instance") >> tctl_wait_start(dir, 'script') >> check_ok(test_i, dir, 'status', 'script', 0, nil, "is = running") >>=20 >>=20 >=20 > I propose to make the code of the test a bit more uniform and use a > meaningful instance file name: >=20 > diff --git a/test/app-tap/tarantoolctl.test.lua = b/test/app-tap/tarantoolctl.test.lua > index 428b074e2..7d7c63371 100755 > --- a/test/app-tap/tarantoolctl.test.lua > +++ b/test/app-tap/tarantoolctl.test.lua > @@ -163,15 +163,14 @@ test:plan(7) > -- must be stopped afterwards > do > local dir =3D fio.tempdir() > - local code =3D [[ box.cfg{memtx_memory =3D 104857600} ]] > - create_script(dir, 'script.lua', code) > - create_script(dir, 'init.lua', [[ print('Hi!') ]]) > + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory =3D = 104857600} ]]) > + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) >=20 > local status, err =3D pcall(function() > test:test("basic test", function(test_i) > test_i:plan(18) > - check_ok(test_i, dir, 'start', 'init.lua', 1, nil, = "Starting instance init...", > - "Plaese, call box.cfg{} within your instance") > + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, = "Starting instance", > + "box.cfg() is not called in an instance file") > check_ok(test_i, dir, 'start', 'script', 0, nil, = "Starting instance") > tctl_wait_start(dir, 'script') > check_ok(test_i, dir, 'status', 'script', 0, nil, "is = running=E2=80=9D) - local code =3D [[ box.cfg{memtx_memory =3D 104857600} ]] - create_script(dir, 'script.lua', code) + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory =3D = 104857600} ]]) + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) =20 local status, err =3D pcall(function() test:test("basic test", function(test_i) - test_i:plan(16) + test_i:plan(18) + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, = "Starting instance", + "box.cfg() is not called in an instance file=E2=80=9D= ) commit 834545cc83965f6d612fcccd39dda03074e7f227 Author: Roman Khabibov Date: Mon Mar 25 20:52:05 2019 +0300 tarantoolctl: raise error when box.cfg isn't called =20 There was no check whether box.cfg{} was initialized in an instance. If so, an error should be raised. =20 Closes #3953 diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 47fcf895f..37ded5333 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -547,8 +547,13 @@ local function start() end os.exit(1) end - local old_call =3D getmetatable(box.cfg).__call - getmetatable(box.cfg).__call =3D function(old_cfg, cfg) + local box_cfg_mt =3D getmetatable(box.cfg) + if box_cfg_mt =3D=3D nil then + log.error('box.cfg() is not called in an instance file') + os.exit(1) + end + local old_call =3D box_cfg_mt.__call + box_cfg_mt.__call =3D function(old_cfg, cfg) if old_cfg.pid_file ~=3D nil and cfg ~=3D nil and cfg.pid_file = ~=3D nil then cfg.pid_file =3D old_cfg.pid_file end diff --git a/test/app-tap/tarantoolctl.test.lua = b/test/app-tap/tarantoolctl.test.lua index db046e03f..7d7c63371 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -163,12 +163,14 @@ test:plan(7) -- must be stopped afterwards do local dir =3D fio.tempdir() - local code =3D [[ box.cfg{memtx_memory =3D 104857600} ]] - create_script(dir, 'script.lua', code) + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory =3D = 104857600} ]]) + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) =20 local status, err =3D pcall(function() test:test("basic test", function(test_i) - test_i:plan(16) + test_i:plan(18) + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, = "Starting instance", + "box.cfg() is not called in an instance file") check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting = instance") tctl_wait_start(dir, 'script') check_ok(test_i, dir, 'status', 'script', 0, nil, "is = running")