2
2
3
3
from redis .exceptions import ResponseError
4
4
5
+ from .conftest import skip_if_server_version_lt
6
+
5
7
function = "redis.register_function('myfunc', function(keys, args) return args[1] end)"
6
8
function2 = "redis.register_function('hello', function() return 'Hello World' end)"
7
9
set_function = "redis.register_function('set', function(keys, args) \
10
12
return redis.call('GET', keys[1]) end)"
11
13
12
14
13
- @pytest .mark .onlynoncluster
14
- # @skip_if_server_version_lt("7.0.0") turn on after redis 7 release
15
+ @skip_if_server_version_lt ("7.0.0" )
15
16
class TestFunction :
16
17
@pytest .fixture (autouse = True )
17
- def reset_functions (self , unstable_r ):
18
- unstable_r .function_flush ()
18
+ def reset_functions (self , r ):
19
+ r .function_flush ()
19
20
20
- def test_function_load (self , unstable_r ):
21
- assert unstable_r .function_load ("Lua" , "mylib" , function )
22
- assert unstable_r .function_load ("Lua" , "mylib" , function , replace = True )
21
+ def test_function_load (self , r ):
22
+ assert r .function_load ("Lua" , "mylib" , function )
23
+ assert r .function_load ("Lua" , "mylib" , function , replace = True )
23
24
with pytest .raises (ResponseError ):
24
- unstable_r .function_load ("Lua" , "mylib" , function )
25
+ r .function_load ("Lua" , "mylib" , function )
25
26
with pytest .raises (ResponseError ):
26
- unstable_r .function_load ("Lua" , "mylib2" , function )
27
+ r .function_load ("Lua" , "mylib2" , function )
27
28
28
- def test_function_delete (self , unstable_r ):
29
- unstable_r .function_load ("Lua" , "mylib" , set_function )
29
+ def test_function_delete (self , r ):
30
+ r .function_load ("Lua" , "mylib" , set_function )
30
31
with pytest .raises (ResponseError ):
31
- unstable_r .function_load ("Lua" , "mylib" , set_function )
32
- assert unstable_r .fcall ("set" , 1 , "foo" , "bar" ) == "OK"
33
- assert unstable_r .function_delete ("mylib" )
32
+ r .function_load ("Lua" , "mylib" , set_function )
33
+ assert r .fcall ("set" , 1 , "foo" , "bar" ) == "OK"
34
+ assert r .function_delete ("mylib" )
34
35
with pytest .raises (ResponseError ):
35
- unstable_r .fcall ("set" , 1 , "foo" , "bar" )
36
- assert unstable_r .function_load ("Lua" , "mylib" , set_function )
36
+ r .fcall ("set" , 1 , "foo" , "bar" )
37
+ assert r .function_load ("Lua" , "mylib" , set_function )
37
38
38
- def test_function_flush (self , unstable_r ):
39
- unstable_r .function_load ("Lua" , "mylib" , function )
40
- assert unstable_r .fcall ("myfunc" , 0 , "hello" ) == "hello"
41
- assert unstable_r .function_flush ()
39
+ def test_function_flush (self , r ):
40
+ r .function_load ("Lua" , "mylib" , function )
41
+ assert r .fcall ("myfunc" , 0 , "hello" ) == "hello"
42
+ assert r .function_flush ()
42
43
with pytest .raises (ResponseError ):
43
- unstable_r .fcall ("myfunc" , 0 , "hello" )
44
+ r .fcall ("myfunc" , 0 , "hello" )
44
45
with pytest .raises (ResponseError ):
45
- unstable_r .function_flush ("ABC" )
46
+ r .function_flush ("ABC" )
46
47
47
- def test_function_list (self , unstable_r ):
48
- unstable_r .function_load ("Lua" , "mylib" , function )
48
+ @pytest .mark .onlynoncluster
49
+ def test_function_list (self , r ):
50
+ r .function_load ("Lua" , "mylib" , function )
49
51
res = [
50
52
[
51
53
"library_name" ,
@@ -58,37 +60,61 @@ def test_function_list(self, unstable_r):
58
60
[["name" , "myfunc" , "description" , None ]],
59
61
],
60
62
]
61
- assert unstable_r .function_list () == res
62
- assert unstable_r .function_list (library = "*lib" ) == res
63
- assert unstable_r .function_list (withcode = True )[0 ][9 ] == function
63
+ assert r .function_list () == res
64
+ assert r .function_list (library = "*lib" ) == res
65
+ assert r .function_list (withcode = True )[0 ][9 ] == function
66
+
67
+ @pytest .mark .onlycluster
68
+ def test_function_list_on_cluster (self , r ):
69
+ r .function_load ("Lua" , "mylib" , function )
70
+ function_list = [
71
+ [
72
+ "library_name" ,
73
+ "mylib" ,
74
+ "engine" ,
75
+ "LUA" ,
76
+ "description" ,
77
+ None ,
78
+ "functions" ,
79
+ [["name" , "myfunc" , "description" , None ]],
80
+ ],
81
+ ]
82
+ primaries = r .get_primaries ()
83
+ res = {}
84
+ for node in primaries :
85
+ res [node .name ] = function_list
86
+ assert r .function_list () == res
87
+ assert r .function_list (library = "*lib" ) == res
88
+ node = primaries [0 ].name
89
+ assert r .function_list (withcode = True )[node ][0 ][9 ] == function
64
90
65
- def test_fcall (self , unstable_r ):
66
- unstable_r .function_load ("Lua" , "mylib" , set_function )
67
- unstable_r .function_load ("Lua" , "mylib2" , get_function )
68
- assert unstable_r .fcall ("set" , 1 , "foo" , "bar" ) == "OK"
69
- assert unstable_r .fcall ("get" , 1 , "foo" ) == "bar"
91
+ def test_fcall (self , r ):
92
+ r .function_load ("Lua" , "mylib" , set_function )
93
+ r .function_load ("Lua" , "mylib2" , get_function )
94
+ assert r .fcall ("set" , 1 , "foo" , "bar" ) == "OK"
95
+ assert r .fcall ("get" , 1 , "foo" ) == "bar"
70
96
with pytest .raises (ResponseError ):
71
- unstable_r .fcall ("myfunc" , 0 , "hello" )
97
+ r .fcall ("myfunc" , 0 , "hello" )
72
98
73
- def test_fcall_ro (self , unstable_r ):
74
- unstable_r .function_load ("Lua" , "mylib" , function )
75
- assert unstable_r .fcall_ro ("myfunc" , 0 , "hello" ) == "hello"
76
- unstable_r .function_load ("Lua" , "mylib2" , set_function )
99
+ def test_fcall_ro (self , r ):
100
+ r .function_load ("Lua" , "mylib" , function )
101
+ assert r .fcall_ro ("myfunc" , 0 , "hello" ) == "hello"
102
+ r .function_load ("Lua" , "mylib2" , set_function )
77
103
with pytest .raises (ResponseError ):
78
- unstable_r .fcall_ro ("set" , 1 , "foo" , "bar" )
104
+ r .fcall_ro ("set" , 1 , "foo" , "bar" )
79
105
80
- def test_function_dump_restore (self , unstable_r ):
81
- unstable_r .function_load ("Lua" , "mylib" , set_function )
82
- payload = unstable_r .function_dump ()
83
- assert unstable_r .fcall ("set" , 1 , "foo" , "bar" ) == "OK"
84
- unstable_r .function_delete ("mylib" )
106
+ def test_function_dump_restore (self , r ):
107
+ r .function_load ("Lua" , "mylib" , set_function )
108
+ payload = r .function_dump ()
109
+ assert r .fcall ("set" , 1 , "foo" , "bar" ) == "OK"
110
+ r .function_delete ("mylib" )
85
111
with pytest .raises (ResponseError ):
86
- unstable_r .fcall ("set" , 1 , "foo" , "bar" )
87
- assert unstable_r .function_restore (payload )
88
- assert unstable_r .fcall ("set" , 1 , "foo" , "bar" ) == "OK"
89
- unstable_r .function_load ("Lua" , "mylib2" , get_function )
90
- assert unstable_r .fcall ("get" , 1 , "foo" ) == "bar"
91
- unstable_r .function_delete ("mylib" )
92
- assert unstable_r .function_restore (payload , "FLUSH" )
112
+ r .fcall ("set" , 1 , "foo" , "bar" )
113
+ assert r .function_restore (payload )
114
+ assert r .fcall ("set" , 1 , "foo" , "bar" ) == "OK"
115
+ r .function_load ("Lua" , "mylib2" , get_function )
116
+ assert r .fcall ("get" , 1 , "foo" ) == "bar"
117
+ r .function_delete ("mylib" )
118
+ assert r .function_restore (payload , "FLUSH" )
93
119
with pytest .raises (ResponseError ):
94
- unstable_r .fcall ("get" , 1 , "foo" )
120
+ r .fcall ("get" , 1 , "foo" )
0 commit comments