/
test_fuzzing.py
203 lines (159 loc) · 5.76 KB
/
test_fuzzing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
"""
This file is part of RedisRaft.
Copyright (c) 2020 Redis Labs
RedisRaft is dual licensed under the GNU General Public License version 3
(AGPLv3) or the Redis Source Available License (RSAL).
"""
import random
import logging
import threading
import time
import pytest
from redis import ResponseError, RedisError
from fixtures import cluster, workload
from workload import MultiWithLargeReply, MonotonicIncrCheck
def test_fuzzing_with_restarts(cluster):
"""
Basic Raft fuzzer test
"""
nodes = 3
cycles = 100
cluster.create(nodes)
for i in range(cycles):
assert cluster.raft_exec('INCRBY', 'counter', 1) == i + 1
logging.info('---------- Executed INCRBY # %s', i)
if i % 7 == 0:
r = random.randint(1, nodes)
logging.info('********** Restarting node %s **********', r)
cluster.node(r).restart()
cluster.node(r).wait_for_election()
logging.info('********** Node %s is UP **********', r)
assert int(cluster.raft_exec('GET', 'counter')) == cycles
def test_fuzzing_with_restarts_and_rewrites(cluster):
"""
Counter fuzzer with log rewrites.
"""
nodes = 3
cycles = 100
cluster.create(nodes)
# Randomize max log entries
for node in cluster.nodes.values():
node.client.execute_command(
'RAFT.CONFIG', 'SET', 'raft-log-max-file-size',
str(random.randint(1000, 2000)))
for i in range(cycles):
assert cluster.raft_exec('INCRBY', 'counter', 1) == i + 1
logging.info('---------- Executed INCRBY # %s', i)
if random.randint(1, 7) == 1:
r = random.randint(1, nodes)
logging.info('********** Restarting node %s **********', r)
cluster.node(r).restart()
cluster.node(r).wait_for_election()
logging.info('********** Node %s is UP **********', r)
assert int(cluster.raft_exec('GET', 'counter')) == cycles
def test_fuzzing_with_config_changes(cluster):
"""
Basic Raft fuzzer test
"""
nodes = 5
cycles = 100
cluster.create(nodes)
for i in range(cycles):
assert cluster.raft_exec('INCRBY', 'counter', 1) == i + 1
if random.randint(1, 7) == 1:
try:
node_id = cluster.random_node_id()
cluster.remove_node(node_id)
except ResponseError:
continue
cluster.add_node().wait_for_node_voting()
assert int(cluster.raft_exec('GET', 'counter')) == cycles
def test_fuzzing_with_proxy_multi_and_restarts(cluster, workload):
"""
Test proxy with transaction safety and random node restarts.
"""
nodes = 3
cycles = 20
thread_count = 200
cluster.create(nodes, raft_args={'raftize-all-commands': 'yes',
'follower-proxy': 'yes'})
workload.start(thread_count, cluster, MultiWithLargeReply)
for i in range(cycles):
time.sleep(1)
try:
logging.info('Cycle %s: %s', i, workload.stats())
cluster.random_node().restart()
except ResponseError as err:
logging.error('Remove node: %s', err)
continue
logging.info('All cycles finished')
workload.stop()
def test_proxy_with_multi_and_reconnections(cluster, workload):
"""
Test proxy mode with MULTI transactions safety checks and
reconnections (dropping clients with CLIENT KILL).
"""
thread_count = 100
cycles = 20
cluster.create(3, raft_args={'follower-proxy': 'yes',
'raftize-all-commands': 'yes'})
workload.start(thread_count, cluster, MultiWithLargeReply)
for _ in range(cycles):
time.sleep(1)
logging.info('Initiating client kill cycle')
cluster.leader_node().client.execute_command(
'CLIENT', 'KILL', 'TYPE', 'normal')
logging.info('All cycles finished')
workload.stop()
def test_stale_reads_on_restarts(cluster, workload):
"""
Test proxy mode with MULTI transactions safety checks and
reconnections (dropping clients with CLIENT KILL).
"""
thread_count = 50
cycles = 20
cluster.create(3, raft_args={'follower-proxy': 'yes',
'raftize-all-commands': 'yes'})
workload.start(thread_count, cluster, MonotonicIncrCheck)
for _ in range(cycles):
time.sleep(1)
cluster.restart()
logging.info('All cycles finished')
workload.stop()
@pytest.mark.slow
def test_proxy_stability_under_load(cluster, workload):
"""
Test stability of the cluster with follower proxy under load.
"""
thread_count = 500
duration = 300
cluster.create(5, raft_args={'follower-proxy': 'yes',
'raftize-all-commands': 'yes'})
workload.start(thread_count, cluster, MultiWithLargeReply)
# Monitor progress
start = time.time()
last_commit_index = 0
while start + duration > time.time():
time.sleep(2)
new_commit_index = cluster.node(cluster.leader).commit_index()
assert new_commit_index > last_commit_index
last_commit_index = new_commit_index
workload.stop()
@pytest.mark.slow
def test_stability_with_snapshots_and_restarts(cluster, workload):
"""
Test stability of the cluster with frequent snapshoting.
"""
thread_count = 100
duration = 300
cluster.create(5, raft_args={'follower-proxy': 'yes',
'raftize-all-commands': 'yes',
'raft-log-max-file-size': '2000'})
workload.start(thread_count, cluster, MultiWithLargeReply)
# Monitor progress
start = time.time()
last_commit_index = 0
while start + duration > time.time():
time.sleep(2)
cluster.random_node().restart()
workload.stop()