From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: [PATCH v2] tarantoolctl: return an error on enter to a dead socket. From: Serge Petrenko In-Reply-To: <20180821122835.6w3kyvlznpxjxhij@esperanza> Date: Tue, 21 Aug 2018 15:51:57 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <17F09AB8-AD92-46D6-BB41-6FF109C336CA@tarantool.org> References: <20180821065621.27693-1-sergepetrenko@tarantool.org> <20180821122835.6w3kyvlznpxjxhij@esperanza> To: Vladimir Davydov Cc: kostja@tarantool.org, tarantool-patches@freelists.org List-ID: > 21 =D0=B0=D0=B2=D0=B3. 2018 =D0=B3., =D0=B2 15:28, Vladimir Davydov = =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BB(=D0=B0= ): >=20 > On Tue, Aug 21, 2018 at 09:56:21AM +0300, Serge Petrenko wrote: >> +-- check enter >> +do >> + local dir =3D fio.tempdir() >> + >> + local code =3D [[ box.cfg{} ]] >> + create_script(dir, 'script.lua', code) >> + >> + local status, err =3D pcall(function() >> + test:test("check error codes in case of enter", = function(test_i) >> + test_i:plan(10) >> + check_ok(test_i, dir, 'enter', 'script', 1, nil, "Can't = connect to") >> + local console_sock =3D 'script.control' >> + console_sock =3D fio.pathjoin(dir, console_sock) >> + test_i:is(fio.path.exists(console_sock), false, = "directory clean") >> + check_ok(test_i, dir, 'start', 'script', 0) >> + tctl_wait_start(dir, 'script') >> + test_i:is(fio.path.exists(console_sock), true, >> + "unix socket created") >> + check_ok(test_i, dir, 'stop', 'script', 0) >> + wait_delete(console_sock) >=20 > There's tctl_wait_stop() for this. Yes, fixed. New diff is below. >=20 > Anyway, why do you need to start/stop instance before trying to enter > it? AFAIU you just want to check that 'tarantoolctl enter' returns an > error when called on a closed socket so the code below should be = enough. I wanted to stress that I=E2=80=99m using a correct path to socket. Not = just creating some Random file at some random place and then expecting `tarantoolctl enter` = to fail. Also test that there is no socket after `tarantoolctl stop` was a = request by Kostja For previous patch, but it is irrelevant now. We can remove it, if you = want, but I believe it=E2=80=99s some extra coverage, nothing wrong with that. >> + test_i:is(fio.path.exists(console_sock), false, >> + "remove unix socket upon exit") >> + fio.open(console_sock, 'O_CREAT') >> + test_i:is(fio.path.exists(console_sock), true, "file = created") >> + check_ok(test_i, dir, 'enter', 'script', 1, nil, "Can't = connect to") >> + fio.unlink(console_sock) >> + end) >> + end) >> + >> + cleanup_instance(dir, 'script') >> + recursive_rmdir(dir) >> + >> + if status =3D=3D false then >> + print(("Error: %s"):format(err)) >> + os.exit() >> + end >> +end >> + extra/dist/tarantoolctl.in | 19 +++++++++++------- test/app-tap/tarantoolctl.test.lua | 40 = +++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 70747bd0c..6b6e78cd2 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -638,15 +638,20 @@ local function enter() end return 1 end - - local cmd =3D string.format( - "require('console').connect('%s', { connect_timeout =3D %s })", - console_sock, TIMEOUT_INFINITY - ) - - console.on_start(function(self) self:eval(cmd) end) + local status, ret + console.on_start(function(self) + status, ret =3D pcall(console.connect, console_sock, + {connect_timeout =3D TIMEOUT_INFINITY}) + if not status then + log.error("Can't connect to %s (%s)", console_sock_path, = ret) + self.running =3D false + end + end) console.on_client_disconnect(function(self) self.running =3D false = end) console.start() + if not status then + return 1 + end return 0 end =20 diff --git a/test/app-tap/tarantoolctl.test.lua = b/test/app-tap/tarantoolctl.test.lua index ac9a208ca..64f2aa7e7 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -157,7 +157,7 @@ local function check_ok(test, dir, cmd, args, e_res, = e_stdout, e_stderr) end =20 local test =3D tap.test('tarantoolctl') -test:plan(6) +test:plan(7) =20 -- basic start/stop test -- must be stopped afterwards @@ -258,6 +258,44 @@ do end end =20 +-- check enter +do + local dir =3D fio.tempdir() + + local code =3D [[ box.cfg{} ]] + create_script(dir, 'script.lua', code) + + local status, err =3D pcall(function() + test:test("check error codes in case of enter", = function(test_i) + test_i:plan(10) + check_ok(test_i, dir, 'enter', 'script', 1, nil, "Can't = connect to") + local console_sock =3D 'script.control' + console_sock =3D fio.pathjoin(dir, console_sock) + test_i:is(fio.path.exists(console_sock), false, "directory = clean") + check_ok(test_i, dir, 'start', 'script', 0) + tctl_wait_start(dir, 'script') + test_i:is(fio.path.exists(console_sock), true, + "unix socket created") + check_ok(test_i, dir, 'stop', 'script', 0) + tctl_wait_stop(dir, 'script') + test_i:is(fio.path.exists(console_sock), false, + "remove unix socket upon exit") + fio.open(console_sock, 'O_CREAT') + test_i:is(fio.path.exists(console_sock), true, "file = created") + check_ok(test_i, dir, 'enter', 'script', 1, nil, "Can't = connect to") + fio.unlink(console_sock) + end) + end) + + cleanup_instance(dir, 'script') + recursive_rmdir(dir) + + if status =3D=3D false then + print(("Error: %s"):format(err)) + os.exit() + end +end + -- check basic help do local dir =3D fio.tempdir() --=20 2.15.2 (Apple Git-101.1)