From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, vdavydov.dev@gmail.com Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org> Subject: [PATCH v1 1/1] box: allow box.session{.exists, .fd} without args Date: Wed, 20 Mar 2019 18:18:33 +0300 [thread overview] Message-ID: <e66f604363e5b557491d08a57e0dc30808cc3570.1553094901.git.kshcherbatov@tarantool.org> (raw) Allow to call box.session.exists() and box.session.fd() without any arguments. In such case, current session is used. The box.session.peer() already support such feature, so we need it to be consistent. Closes #4021 http://github.com/tarantool/tarantool/tree/kshch/gh-4021-optional-session-id https://github.com/tarantool/tarantool/issues/4021 --- src/box/lua/session.c | 19 +++++++++++++------ test/box-tap/session.test.lua | 5 +++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/box/lua/session.c b/src/box/lua/session.c index a4ddb201c..c0ac4917b 100644 --- a/src/box/lua/session.c +++ b/src/box/lua/session.c @@ -214,11 +214,15 @@ lbox_session_su(struct lua_State *L) static int lbox_session_exists(struct lua_State *L) { - if (lua_gettop(L) != 1) + if (lua_gettop(L) > 1) luaL_error(L, "session.exists(sid): bad arguments"); - uint64_t sid = luaL_checkint64(L, -1); - lua_pushboolean(L, session_find(sid) != NULL); + struct session *session; + if (lua_gettop(L) == 1) + session = session_find(luaL_checkint64(L, -1)); + else + session = current_session(); + lua_pushboolean(L, session != NULL); return 1; } @@ -228,11 +232,14 @@ lbox_session_exists(struct lua_State *L) static int lbox_session_fd(struct lua_State *L) { - if (lua_gettop(L) != 1) + if (lua_gettop(L) > 1) luaL_error(L, "session.fd(sid): bad arguments"); - uint64_t sid = luaL_checkint64(L, -1); - struct session *session = session_find(sid); + struct session *session; + if (lua_gettop(L) == 1) + session = session_find(luaL_checkint64(L, -1)); + else + session = current_session(); if (session == NULL) luaL_error(L, "session.fd(): session does not exist"); lua_pushinteger(L, session_fd(session)); diff --git a/test/box-tap/session.test.lua b/test/box-tap/session.test.lua index 857bc643b..b6b08d209 100755 --- a/test/box-tap/session.test.lua +++ b/test/box-tap/session.test.lua @@ -15,7 +15,7 @@ session = box.session space = box.schema.space.create('tweedledum') index = space:create_index('primary', { type = 'hash' }) -test:plan(55) +test:plan(56) --- --- Check that Tarantool creates ADMIN session for #! script @@ -23,7 +23,7 @@ test:plan(55) test:ok(session.exists(session.id()), "session is created") test:isnil(session.peer(session.id()), "session.peer") local ok, err = pcall(session.exists) -test:is(err, "session.exists(sid): bad arguments", "exists bad args #1") +test:ok(ok, "session.exists()") ok, err = pcall(session.exists, 1, 2, 3) test:is(err, "session.exists(sid): bad arguments", "exists bad args #2") test:ok(not session.exists(1234567890), "session doesn't exist") @@ -166,6 +166,7 @@ test:is( ) local uri = inspector:eval('session', 'box.cfg.listen')[1] conn = net.box.connect(uri) +test:ok(conn:eval("return box.session.fd()"), "get session fd") test:ok(conn:eval("return box.session.exists(box.session.id())"), "remote session exist check") test:isnt(conn:eval("return box.session.peer(box.session.id())"), nil, "remote session peer check") test:ok(conn:eval("return box.session.peer() == box.session.peer(box.session.id())"), "remote session peer check") -- 2.21.0
next reply other threads:[~2019-03-20 15:18 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-03-20 15:18 Kirill Shcherbatov [this message] 2019-03-26 16:14 ` Vladimir Davydov
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=e66f604363e5b557491d08a57e0dc30808cc3570.1553094901.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH v1 1/1] box: allow box.session{.exists, .fd} without args' \ /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