Add tests for script timeouts.

This commit is contained in:
Alex Roitman 2019-04-24 17:17:49 -07:00
parent 49111a4dce
commit 2020f537dc
1 changed files with 33 additions and 0 deletions

View File

@ -13,6 +13,7 @@ func subTestTimeout(t *testing.T, mc *mockServer) {
runStep(t, mc, "session set/unset", timeout_session_set_unset_test)
runStep(t, mc, "session spatial", timeout_session_spatial_test)
runStep(t, mc, "session search", timeout_session_search_test)
runStep(t, mc, "session scripts", timeout_session_scripts_test)
runStep(t, mc, "command spatial", timeout_command_spatial_test)
runStep(t, mc, "command search", timeout_command_search_test)
}
@ -112,3 +113,35 @@ func timeout_command_search_test(mc *mockServer) (err error) {
{"SEARCH", "mykey", "TIMEOUT", "0.000001", "MATCH", "val:*", "COUNT"}, {"ERR timeout"},
})
}
func timeout_session_scripts_test(mc *mockServer) (err error) {
script := `
local clock = os.clock
local function sleep(n)
local t0 = clock()
while clock() - t0 <= n do end
end
sleep(0.5)
`
sha := "e3ce9449853a622327f30c727a6e086ccd91d9d4"
return mc.DoBatch([][]interface{}{
{"SCRIPT LOAD", script}, {sha},
{"EVALSHA", sha, 0}, {nil},
{"EVALROSHA", sha, 0}, {nil},
{"EVALNASHA", sha, 0}, {nil},
{"TIMEOUT", "0.1"}, {"OK"},
{"EVALSHA", sha, 0}, {"ERR timeout"},
{"EVALROSHA", sha, 0}, {"ERR timeout"},
{"EVALNASHA", sha, 0}, {"ERR timeout"},
{"TIMEOUT", "0.9"}, {"OK"},
{"EVALSHA", sha, 0}, {nil},
{"EVALROSHA", sha, 0}, {nil},
{"EVALNASHA", sha, 0}, {nil},
})
}