Skip to content
Snippets Groups Projects
Commit c3c6d3fc authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy Committed by Kirill Yukhin
Browse files

errinj: provide 'get' method in Lua

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
parent 16c40444
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......
......@@ -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
...
......@@ -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')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment