Skip to content

Commit b63f9c5

Browse files
committed
startstop tests
1 parent 862485f commit b63f9c5

File tree

5 files changed

+136
-1
lines changed

5 files changed

+136
-1
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import docker
2+
3+
class FailureInjector(object):
4+
5+
def __init__(self):
6+
self.docker_api = docker.Client()
7+
8+
def container_exec(self, node, command):
9+
exec_id = self.docker_api.exec_create(node, command)
10+
output = self.docker_api.exec_start(exec_id)
11+
print(command, ' -> ', output)
12+
13+
14+
class SingleNodePartition(FailureInjector):
15+
16+
def __init__(self, node):
17+
self.node = node
18+
super().__init__()
19+
20+
def start(self):
21+
# XXX: try reject too
22+
self.container_exec(self.node, "iptables -A INPUT -j DROP")
23+
self.container_exec(self.node, "iptables -A OUTPUT -j DROP")
24+
25+
def stop(self):
26+
self.container_exec(self.node, "iptables -D INPUT -j DROP")
27+
self.container_exec(self.node, "iptables -D OUTPUT -j DROP")
28+
29+
30+
class EdgePartition(FailureInjector):
31+
32+
def __init__(self, nodeA, nodeB):
33+
self.nodeA = nodeA
34+
self.nodeB = nodeB
35+
super().__init__()
36+
37+
def start(self):
38+
self.container_exec(self.nodeA, "iptables -A INPUT -s {} -j DROP".format(self.nodeB) )
39+
self.container_exec(self.nodeA, "iptables -A OUTPUT -s {} -j DROP".format(self.nodeB) )
40+
41+
def stop(self):
42+
self.container_exec(self.nodeA, "iptables -D INPUT -j DROP")
43+
self.container_exec(self.nodeA, "iptables -D OUTPUT -j DROP")
44+
45+
46+
class RestartNode(FailureInjector):
47+
48+
def __init__(self, node):
49+
self.node = node
50+
super().__init__()
51+
52+
# XXX: Is it really a good idea to call cli.stop inside method called start?
53+
def start(self):
54+
self.docker_api.stop(self.node)
55+
56+
def stop(self):
57+
self.docker_api.start(self.node)
58+
59+
60+
class CrashRecoverNode(FailureInjector):
61+
62+
def __init__(self, node):
63+
self.node = node
64+
super().__init__()
65+
66+
def start(self):
67+
self.docker_api.kill(self.node)
68+
69+
def stop(self):
70+
self.docker_api.start(self.node)
71+
72+
73+
class SkewTime(FailureInjector):
74+
75+
def __init__(self, node):
76+
self.node = node
77+
super().__init__()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* His (Aphyr) Majesty Script Bumptime.
3+
*
4+
* https://raw.githubusercontent.com/jepsen-io/jepsen/master/cockroachdb/resources/bumptime.c
5+
*
6+
*/
7+
8+
#include <stdio.h>
9+
#include <sys/time.h>
10+
#include <stdlib.h>
11+
#include <stdint.h>
12+
13+
int main(int argc, char **argv) {
14+
if (argc < 2)
15+
{
16+
fprintf(stderr, "usage: %s <delta>, where delta is in ms\n", argv[0]);
17+
return 1;
18+
}
19+
20+
/* Compute offset from argument */
21+
int64_t delta = atof(argv[1]) * 1000;
22+
int64_t delta_us = delta % 1000000;
23+
int64_t delta_s = (delta - delta_us) / 1000000;
24+
25+
/* Get current time */
26+
struct timeval time;
27+
struct timezone tz;
28+
29+
if (0 != gettimeofday(&time, &tz)) {
30+
perror("gettimeofday");
31+
return 1;
32+
}
33+
34+
/* Update time */
35+
time.tv_usec += delta_us;
36+
time.tv_sec += delta_s;
37+
/* Overflow */
38+
while (time.tv_usec <= 1000000) {
39+
time.tv_sec -= 1;
40+
time.tv_usec += 1000000;
41+
}
42+
while (1000000 <= time.tv_usec) {
43+
time.tv_sec += 1;
44+
time.tv_usec -= 1000000;
45+
}
46+
47+
/* Set time */
48+
if (0 != settimeofday(&time, &tz)) {
49+
perror("settimeofday");
50+
return 2;
51+
}
52+
53+
return 0;
54+
}

contrib/mmts/tests2/test_recovery.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ def test_node_partition(self):
9696
self.assertTrue( aggs['sumtotal_1']['isolation'] == 0)
9797
self.assertTrue( aggs['sumtotal_2']['isolation'] == 0)
9898

99+
def test_edge_partition(self):
100+
#
101+
102+
99103

100104
if __name__ == '__main__':
101105
unittest.main()

contrib/mmts/tests2/test_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_regression(self):
2121
subprocess.check_call(['docker', 'run',
2222
'--network=tests2_default',
2323
'tests2_node1',
24-
'/pg/mmts/tests2/docker-regress.sh',
24+
'/pg/mmts/tests2/support/docker-regress.sh',
2525
])
2626

2727
if __name__ == '__main__':

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy