Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-09-26 23:26:46 +03:00
|
|
|
func subTestScripts(g *testGroup) {
|
|
|
|
g.regSubTest("BASIC", scripts_BASIC_test)
|
|
|
|
g.regSubTest("ATOMIC", scripts_ATOMIC_test)
|
|
|
|
g.regSubTest("READONLY", scripts_READONLY_test)
|
|
|
|
g.regSubTest("NONATOMIC", scripts_NONATOMIC_test)
|
2022-11-10 00:33:37 +03:00
|
|
|
g.regSubTest("VULN", scripts_VULN_test)
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func scripts_BASIC_test(mc *mockServer) error {
|
|
|
|
return mc.DoBatch([][]interface{}{
|
|
|
|
{"EVAL", "return 2 + 2", 0}, {"4"},
|
|
|
|
{"SCRIPT LOAD", "return 2 + 2"}, {"2dd1b44209ecb49617af05caf0491390a03c1cc4"},
|
|
|
|
{"SCRIPT EXISTS", "2dd1b44209ecb49617af05caf0491390a03c1cc4", "no_script"}, {"[1 0]"},
|
|
|
|
{"EVALSHA", "2dd1b44209ecb49617af05caf0491390a03c1cc4", "0"}, {"4"},
|
|
|
|
{"SCRIPT FLUSH"}, {"OK"},
|
|
|
|
{"SCRIPT EXISTS", "2dd1b44209ecb49617af05caf0491390a03c1cc4", "no_script"}, {"[0 0]"},
|
|
|
|
{"EVAL", "return KEYS[1] .. ' only'", 1, "key1"}, {"key1 only"},
|
|
|
|
{"EVAL", "return KEYS[1] .. ' and ' .. ARGV[1]", 1, "key1", "arg1"}, {"key1 and arg1"},
|
|
|
|
{"EVAL", "return ARGV[1] .. ' and ' .. ARGV[2]", 0, "arg1", "arg2"}, {"arg1 and arg2"},
|
2019-01-05 01:57:00 +03:00
|
|
|
{"EVAL", "return tile38.sha1hex('asdf')", 0}, {"3da541559918a808c2402bba5012f6c60b27661c"},
|
|
|
|
{"EVAL", "return tile38.distance_to(37.7341129, -122.4408378, 37.733, -122.43)", 0}, {"961"},
|
Lua scripting feature. (#224)
* Start on lua scripting
* Implement evalsha, script load, script exists, and script flush
* Type conversions from lua to resp/json.
Refactor to make luastate and luascripts persistent in the controller.
* Change controller.command and all underlying commands to return resp.Value.
Serialize only during the ouput.
* First stab at tile38 call from lua
* Change tile38 into tile38.call in Lua
* Property return errors from scripts
* Minor refactoring. No locking on script run
* Cleanup/refactoring
* Create a pool of 5 lua states, allow for more as needed. Refactor.
* Use safe map for scripts. Add a limit for max number of lua states. Refactor.
* Refactor
* Refactor script commands into atomic, read-only, and non-atomic classes.
Proper locking for all three classes.
Add tests for scripts
* More tests for scripts
* Properly escape newlines in lua-produced errors
* Better test for readonly failure
* Correctly convert ok/err messages between lua and resp.
Add pcall, sha1hex, error_reply, status_reply functions to tile38 namespace in lua.
* Add pcall test. Change writeErr to work with string argument
* Make sure eval/evalsha never attempt to write AOF
* Add eval-set and eval-get to benchmarks
* Fix eval benchmark tests, add more
* Improve benchmarks
* Optimizations and refactoring.
* Add lua memtest
* Typo
* Add dependency
* golint fixes
* gofmt fixes
* Add scripting commands to the core/commands.json
* Use ARGV for args inside lua
2017-10-05 18:20:40 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func scripts_ATOMIC_test(mc *mockServer) error {
|
|
|
|
return mc.DoBatch([][]interface{}{
|
|
|
|
{"EVAL", "return tile38.call('get', KEYS[1], ARGV[1])", "1", "mykey", "myid"}, {nil},
|
|
|
|
{"EVAL", "return tile38.call('set', KEYS[1], ARGV[1], 'point', 33, -115)", "1", "mykey", "myid1"}, {"OK"},
|
|
|
|
{"EVAL", "return tile38.call('get', KEYS[1], ARGV[1], ARGV[2])", "1", "mykey", "myid1", "point"}, {"[33 -115]"},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func scripts_READONLY_test(mc *mockServer) error {
|
|
|
|
return mc.DoBatch([][]interface{}{
|
|
|
|
{"EVALRO", "return tile38.call('get', KEYS[1], ARGV[1])", "1", "mykey", "myid"}, {nil},
|
|
|
|
{"EVALRO", "return tile38.call('set', KEYS[1], ARGV[1], 'point', 33, -115)", "1", "mykey", "myid1"}, {
|
|
|
|
func(v interface{}) (resp, expect interface{}) {
|
|
|
|
s := fmt.Sprintf("%v", v)
|
|
|
|
if strings.Contains(s, "ERR read only") {
|
|
|
|
return v, v
|
|
|
|
}
|
|
|
|
return v, "A lua stack containing 'ERR read only'"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{"EVALRO", "return tile38.pcall('set', KEYS[1], ARGV[1], 'point', 33, -115)", "1", "mykey", "myid1"}, {"ERR read only"},
|
|
|
|
{"SET", "mykey", "myid1", "POINT", 33, -115}, {"OK"},
|
|
|
|
{"EVALRO", "return tile38.call('get', KEYS[1], ARGV[1], ARGV[2])", "1", "mykey", "myid1", "point"}, {"[33 -115]"},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func scripts_NONATOMIC_test(mc *mockServer) error {
|
|
|
|
return mc.DoBatch([][]interface{}{
|
|
|
|
{"EVALNA", "return tile38.call('get', KEYS[1], ARGV[1])", "1", "mykey", "myid"}, {nil},
|
|
|
|
{"EVALNA", "return tile38.call('set', KEYS[1], ARGV[1], 'point', 33, -115)", "1", "mykey", "myid1"}, {"OK"},
|
|
|
|
{"EVALNA", "return tile38.call('get', KEYS[1], ARGV[1], ARGV[2])", "1", "mykey", "myid1", "point"}, {"[33 -115]"},
|
|
|
|
})
|
|
|
|
}
|
2022-11-10 00:33:37 +03:00
|
|
|
|
|
|
|
func scripts_VULN_test(mc *mockServer) error {
|
|
|
|
return mc.DoBatch([][]interface{}{
|
|
|
|
{"EVAL", "return io", "0"}, {nil},
|
|
|
|
{"EVAL", "return file", "0"}, {nil},
|
|
|
|
{"EVAL", "return os.execute", "0"}, {nil},
|
|
|
|
{"EVAL", "return os.getenv", "0"}, {nil},
|
|
|
|
{"EVAL", "return os.clock", "0"}, {"ERR Unsupported lua type: function"},
|
|
|
|
{"EVAL", "return loadfile", "0"}, {nil},
|
2022-11-10 00:50:43 +03:00
|
|
|
{"EVAL", "return tonumber(ARGV[1])", "0", "38"}, {"38"},
|
|
|
|
{"EVAL", "return package", "0"}, {nil},
|
2022-11-10 00:33:37 +03:00
|
|
|
})
|
|
|
|
}
|