8000 Testing script shall raise an error when tests fail. Increase reliabi… · syk-coder/rabbitmq-tutorials@5fba979 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5fba979

Browse files
committed
Testing script shall raise an error when tests fail. Increase reliability - by randomizing test inputs.
1 parent 52d76e2 commit 5fba979

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

test.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
import time
3+
import random
34
import re
45
import subprocess
56
import signal
@@ -8,7 +9,9 @@
89
def run(cmd, verbose=False, **kwargs):
910
if verbose:
1011
print " [s] Running %r" % (cmd,)
11-
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, **kwargs)
12+
p = subprocess.Popen(cmd.split(),
13+
stdout=subprocess.PIPE,
14+
**kwargs)
1215
p.wait()
1316

1417
if verbose:
@@ -23,7 +26,10 @@ def run(cmd, verbose=False, **kwargs):
2326
def spawn(cmd, verbose=False, **kwargs):
2427
if verbose:
2528
print " [r] Waiting for %r" % (cmd,)
26-
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
29+
p = subprocess.Popen(cmd.split(),
30+
stdout=subprocess.PIPE,
31+
stderr=subprocess.PIPE,
32+
**kwargs)
2733
time.sleep(0.4)
2834
return p
2935

@@ -66,20 +72,35 @@ def gen(prog, arg="", **kwargs):
6672

6773
tests = {
6874
'tut1': (gen('send'), gen('receive', java='Recv'), 'Hello World!'),
69-
'tut2': (gen('new_task', arg='xxxxxx'), gen('worker'), 'xxxxxx'),
70-
'tut3': (gen('emit_log', arg='123456'), gen('receive_logs'), '123456'),
75+
'tut2': (gen('new_task', arg='%(arg)s'), < 8000 span class="pl-en">gen('worker'), '%(arg)s'),
76+
'tut3': (gen('emit_log', arg='%(arg)s'), gen('receive_logs'), '%(arg)s'),
7177
}
7278

7379

7480
verbose = len(sys.argv) > 1
81+
errors = 0
7582

7683
for test in sorted(tests.keys()):
77-
(send_progs, recv_progs, mask) = tests[test]
78-
for scwd, scmd in send_progs:
79-
for rcwd, rcmd in recv_progs:
84+
(send_progs, recv_progs, output_mask) = tests[test]
85+
for scwd, send_cmd in send_progs:
86+
for rcwd, recv_cmd in recv_progs:
87+
ctx = {
88+
'arg': 'rand_%s' % (random.randint(1,100),)
89+
}
90+
rcmd = recv_cmd % ctx
91+
scmd = send_cmd % ctx
92+
mask = output_mask % ctx
8093
p = spawn(rcmd, verbose=verbose, cwd=rcwd)
8194
run(scmd, verbose=verbose, cwd=scwd)
8295
if wait(p, mask, verbose=verbose):
8396
print " [+] %s %-20s ok" % (test, scwd+'/'+rcwd)
8497
else:
85-
print " [!] %s %-20s FAILED %r %r" % (test, scwd+'/'+rcwd, rcmd, scmd)
98+
print " [!] %s %-20s FAILED %r %r" % \
99+
(test, scwd+'/'+rcwd, rcmd, scmd)
100+
errors += 1
101+
102+
if errors:
103+
print " [!] %s tests failed" % (errors,)
104+
105+
sys.exit(errors)
106+

0 commit comments

Comments
 (0)
0