Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org, kostja.osipov@gmail.com
Subject: [Tarantool-patches] [PATCH 1/2] errinj: provide 'get' method in Lua
Date: Wed, 27 Nov 2019 00:29:40 +0100	[thread overview]
Message-ID: <da7253ee85c0c352d10826775d03ffa46e223ff8.1574810891.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1574810891.git.v.shpilevoy@tarantool.org>

Error injections are used to simulate an error. They are
represented as a flag, or a number, and are used in Lua tests. But
they don't have any feedback. That makes impossible to use the
injections to check that something has happened. Something very
needed to be checked, and impossible to check in a different way.

More certainly, the patch is motivated by a necessity to count
loaded dynamic libraries to ensure, that they are loaded and
unloaded when expected. This is impossible to do in a platform
independent way. But an error injection as a debug-only counter
would solve the problem.

Needed for #4648
---
 src/box/lua/error.cc     | 37 ++++++++++++++++++++-------
 test/box/errinj.result   | 55 ++++++++++++++++++++++++++++++++++++++++
 test/box/errinj.test.lua | 17 +++++++++++++
 3 files changed, 100 insertions(+), 9 deletions(-)

diff --git a/src/box/lua/error.cc b/src/box/lua/error.cc
index 230d51dec..fc53a40f4 100644
--- a/src/box/lua/error.cc
+++ b/src/box/lua/error.cc
@@ -184,26 +184,44 @@ lbox_errinj_set(struct lua_State *L)
 	return 1;
 }
 
-static inline int
-lbox_errinj_cb(struct errinj *e, void *cb_ctx)
+static int
+lbox_errinj_push_value(struct lua_State *L, const struct errinj *e)
 {
-	struct lua_State *L = (struct lua_State*)cb_ctx;
-	lua_pushstring(L, e->name);
-	lua_newtable(L);
-	lua_pushstring(L, "state");
 	switch (e->type) {
 	case ERRINJ_BOOL:
 		lua_pushboolean(L, e->bparam);
-		break;
+		return 1;
 	case ERRINJ_INT:
 		luaL_pushint64(L, e->iparam);
-		break;
+		return 1;
 	case ERRINJ_DOUBLE:
 		lua_pushnumber(L, e->dparam);
-		break;
+		return 1;
 	default:
 		unreachable();
+		return 0;
 	}
+}
+
+static int
+lbox_errinj_get(struct lua_State *L)
+{
+	char *name = (char*)luaL_checkstring(L, 1);
+	struct errinj *e = errinj_by_name(name);
+	if (e != NULL)
+		return lbox_errinj_push_value(L, e);
+	lua_pushfstring(L, "error: can't find error injection '%s'", name);
+	return 1;
+}
+
+static inline int
+lbox_errinj_cb(struct errinj *e, void *cb_ctx)
+{
+	struct lua_State *L = (struct lua_State*)cb_ctx;
+	lua_pushstring(L, e->name);
+	lua_newtable(L);
+	lua_pushstring(L, "state");
+	lbox_errinj_push_value(L, e);
 	lua_settable(L, -3);
 	lua_settable(L, -3);
 	return 0;
@@ -259,6 +277,7 @@ box_lua_error_init(struct lua_State *L) {
 	static const struct luaL_Reg errinjlib[] = {
 		{"info", lbox_errinj_info},
 		{"set", lbox_errinj_set},
+		{"get", lbox_errinj_get},
 		{NULL, NULL}
 	};
 	/* box.error.injection is not set by register_module */
diff --git a/test/box/errinj.result b/test/box/errinj.result
index a148346e8..40683730c 100644
--- a/test/box/errinj.result
+++ b/test/box/errinj.result
@@ -1724,3 +1724,58 @@ box.schema.user.drop('testg')
 box.space.testg:drop()
 ---
 ...
+--
+-- Errinj:get().
+--
+box.error.injection.get('bad name')
+---
+- 'error: can''t find error injection ''bad name'''
+...
+box.error.injection.set('ERRINJ_WAL_IO', true)
+---
+- ok
+...
+box.error.injection.get('ERRINJ_WAL_IO')
+---
+- true
+...
+box.error.injection.set('ERRINJ_WAL_IO', false)
+---
+- ok
+...
+box.error.injection.get('ERRINJ_WAL_IO')
+---
+- false
+...
+box.error.injection.set('ERRINJ_TUPLE_FORMAT_COUNT', 20)
+---
+- ok
+...
+box.error.injection.get('ERRINJ_TUPLE_FORMAT_COUNT')
+---
+- 20
+...
+box.error.injection.set('ERRINJ_TUPLE_FORMAT_COUNT', -1)
+---
+- ok
+...
+box.error.injection.get('ERRINJ_TUPLE_FORMAT_COUNT')
+---
+- -1
+...
+box.error.injection.set('ERRINJ_RELAY_TIMEOUT', 0.5)
+---
+- ok
+...
+box.error.injection.get('ERRINJ_RELAY_TIMEOUT')
+---
+- 0.5
+...
+box.error.injection.set('ERRINJ_RELAY_TIMEOUT', 0)
+---
+- ok
+...
+box.error.injection.get('ERRINJ_RELAY_TIMEOUT')
+---
+- 0
+...
diff --git a/test/box/errinj.test.lua b/test/box/errinj.test.lua
index 31dd9665b..03c088677 100644
--- a/test/box/errinj.test.lua
+++ b/test/box/errinj.test.lua
@@ -603,3 +603,20 @@ box.session.su('admin')
 box.error.injection.set('ERRINJ_WAL_IO', false)
 box.schema.user.drop('testg')
 box.space.testg:drop()
+
+--
+-- Errinj:get().
+--
+box.error.injection.get('bad name')
+box.error.injection.set('ERRINJ_WAL_IO', true)
+box.error.injection.get('ERRINJ_WAL_IO')
+box.error.injection.set('ERRINJ_WAL_IO', false)
+box.error.injection.get('ERRINJ_WAL_IO')
+box.error.injection.set('ERRINJ_TUPLE_FORMAT_COUNT', 20)
+box.error.injection.get('ERRINJ_TUPLE_FORMAT_COUNT')
+box.error.injection.set('ERRINJ_TUPLE_FORMAT_COUNT', -1)
+box.error.injection.get('ERRINJ_TUPLE_FORMAT_COUNT')
+box.error.injection.set('ERRINJ_RELAY_TIMEOUT', 0.5)
+box.error.injection.get('ERRINJ_RELAY_TIMEOUT')
+box.error.injection.set('ERRINJ_RELAY_TIMEOUT', 0)
+box.error.injection.get('ERRINJ_RELAY_TIMEOUT')
-- 
2.21.0 (Apple Git-122.2)

  reply	other threads:[~2019-11-26 23:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26 23:29 [Tarantool-patches] [PATCH 0/2] Module is not unloaded on function drop Vladislav Shpilevoy
2019-11-26 23:29 ` Vladislav Shpilevoy [this message]
2019-11-27  8:35   ` [Tarantool-patches] [PATCH 1/2] errinj: provide 'get' method in Lua Konstantin Osipov
2019-11-26 23:29 ` [Tarantool-patches] [PATCH 2/2] func: fix not unloading of unused modules Vladislav Shpilevoy
2019-11-27  8:41   ` Konstantin Osipov
2019-11-27 22:24     ` Vladislav Shpilevoy
2019-12-10 14:22 ` [Tarantool-patches] [PATCH 0/2] Module is not unloaded on function drop Kirill Yukhin
2019-12-11 21:36   ` Alexander Turenko
2019-12-11 22:33   ` Vladislav Shpilevoy
2019-12-19  4:50 ` Kirill Yukhin

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=da7253ee85c0c352d10826775d03ffa46e223ff8.1574810891.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja.osipov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 1/2] errinj: provide '\''get'\'' method in Lua' \
    /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