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 D18D626ECA for ; Wed, 1 Aug 2018 10:31:01 -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 HOLDypRpdtPf for ; Wed, 1 Aug 2018 10:31:01 -0400 (EDT) Received: from smtp17.mail.ru (smtp17.mail.ru [94.100.176.154]) (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 902C626D46 for ; Wed, 1 Aug 2018 10:31:01 -0400 (EDT) From: AKhatskevich Subject: [tarantool-patches] [PATCH] Check self arg passed for router objects Date: Wed, 1 Aug 2018 17:30:46 +0300 Message-Id: <20180801143046.3527-1-avkhatskevich@tarantool.org> In-Reply-To: References: 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: v.shpilevoy@tarantool.org, tarantool-patches@freelists.org Raise an exception in case someone calls router like `router.info()` instead of `router:info()`. --- test/multiple_routers/multiple_routers.result | 5 +++++ test/multiple_routers/multiple_routers.test.lua | 3 +++ vshard/router/init.lua | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/test/multiple_routers/multiple_routers.result b/test/multiple_routers/multiple_routers.result index 33f4034..389bf9a 100644 --- a/test/multiple_routers/multiple_routers.result +++ b/test/multiple_routers/multiple_routers.result @@ -201,6 +201,11 @@ routers[5]:call(1, 'read', 'do_select', {2}) --- - [[2, 2]] ... +-- Self checker. +util.check_error(router_2.info) +--- +- Use router:info(...) instead of router.info(...) +... _ = test_run:cmd("switch default") --- ... diff --git a/test/multiple_routers/multiple_routers.test.lua b/test/multiple_routers/multiple_routers.test.lua index 6d470e1..2f159c7 100644 --- a/test/multiple_routers/multiple_routers.test.lua +++ b/test/multiple_routers/multiple_routers.test.lua @@ -76,6 +76,9 @@ vshard.router.call(1, 'read', 'do_select', {1}) router_2:call(1, 'read', 'do_select', {2}) routers[5]:call(1, 'read', 'do_select', {2}) +-- Self checker. +util.check_error(router_2.info) + _ = test_run:cmd("switch default") test_run:cmd("stop server router_1") test_run:cmd("cleanup server router_1") diff --git a/vshard/router/init.lua b/vshard/router/init.lua index 128628b..e0a39b2 100644 --- a/vshard/router/init.lua +++ b/vshard/router/init.lua @@ -860,6 +860,15 @@ local router_mt = { } } +-- +-- Wrap self methods with a sanity checker. +-- +local mt_index = {} +for name, func in pairs(router_mt.__index) do + mt_index[name] = util.generate_self_checker("router", name, router_mt, func) +end +router_mt.__index = mt_index + -- Table which represents this module. local module = {} -- 2.14.1