Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] Return valid lua error for func creation error
@ 2018-11-02 11:30 Georgy Kirichenko
  2018-11-02 13:46 ` [tarantool-patches] " n.pettik
  2018-11-13 11:47 ` Kirill Yukhin
  0 siblings, 2 replies; 3+ messages in thread
From: Georgy Kirichenko @ 2018-11-02 11:30 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Georgy Kirichenko

Return valid lua error if something fail while sql function creation.
---
https://github.com/tarantool/tarantool/issues/3724
https://github.com/tarantool/tarantool/tree/g.kirichenko/gh-3724-return-error-from-func-creation

 src/box/lua/lua_sql.c           |  3 +++
 test/sql/func-recreate.result   | 36 +++++++++++++++++++++++++++++++++
 test/sql/func-recreate.test.lua | 17 ++++++++++++++++
 3 files changed, 56 insertions(+)
 create mode 100644 test/sql/func-recreate.result
 create mode 100644 test/sql/func-recreate.test.lua

diff --git a/src/box/lua/lua_sql.c b/src/box/lua/lua_sql.c
index 9d78679fb..100f53b01 100644
--- a/src/box/lua/lua_sql.c
+++ b/src/box/lua/lua_sql.c
@@ -193,6 +193,9 @@ int lbox_sql_create_function(struct lua_State *L)
 				  NULL, NULL, lua_sql_destroy);
 
 	free(normalized_name);
+	if (rc != 0) {
+		return luaL_error(L, sqlite3ErrStr(rc));
+	}
 	return rc;
 }
 
diff --git a/test/sql/func-recreate.result b/test/sql/func-recreate.result
new file mode 100644
index 000000000..f12cc8d90
--- /dev/null
+++ b/test/sql/func-recreate.result
@@ -0,0 +1,36 @@
+test_run = require('test_run').new()
+---
+...
+engine = test_run:get_cfg('engine')
+---
+...
+box.sql.execute('pragma sql_default_engine=\''..engine..'\'')
+---
+...
+-- Check errors during function create process
+fiber = require('fiber')
+---
+...
+box.internal.sql_create_function('WAITFOR', function (n) fiber.sleep(n) return n end)
+---
+...
+ch = fiber.channel(1)
+---
+...
+_ = fiber.create(function () ch:put(box.sql.execute('select WAITFOR(0.2)')) end)
+---
+...
+fiber.sleep(0.1)
+---
+...
+box.internal.sql_create_function('WAITFOR', function (n) require('fiber').sleep(n) return n end)
+---
+- error: database is locked
+...
+ch:get()
+---
+- - [0.2]
+...
+box.internal.sql_create_function('WAITFOR', function (n) require('fiber').sleep(n) return n end)
+---
+...
diff --git a/test/sql/func-recreate.test.lua b/test/sql/func-recreate.test.lua
new file mode 100644
index 000000000..b105da8cb
--- /dev/null
+++ b/test/sql/func-recreate.test.lua
@@ -0,0 +1,17 @@
+test_run = require('test_run').new()
+engine = test_run:get_cfg('engine')
+box.sql.execute('pragma sql_default_engine=\''..engine..'\'')
+
+-- Check errors during function create process
+fiber = require('fiber')
+box.internal.sql_create_function('WAITFOR', function (n) fiber.sleep(n) return n end)
+
+ch = fiber.channel(1)
+
+_ = fiber.create(function () ch:put(box.sql.execute('select WAITFOR(0.2)')) end)
+fiber.sleep(0.1)
+
+box.internal.sql_create_function('WAITFOR', function (n) require('fiber').sleep(n) return n end)
+ch:get()
+box.internal.sql_create_function('WAITFOR', function (n) require('fiber').sleep(n) return n end)
+
-- 
2.19.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-13 11:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-02 11:30 [tarantool-patches] [PATCH] Return valid lua error for func creation error Georgy Kirichenko
2018-11-02 13:46 ` [tarantool-patches] " n.pettik
2018-11-13 11:47 ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox