Skip to content

Commit

Permalink
Testing script shall raise an error when tests fail. Increase reliabi…
Browse files Browse the repository at this point in the history
…lity - by randomizing test inputs.
  • Loading branch information
majek committed Jul 4, 2011
1 parent 52d76e2 commit 5fba979
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
import time
import random
import re
import subprocess
import signal
Expand All @@ -8,7 +9,9 @@
def run(cmd, verbose=False, **kwargs):
if verbose:
print " [s] Running %r" % (cmd,)
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, **kwargs)
p = subprocess.Popen(cmd.split(),
stdout=subprocess.PIPE,
**kwargs)
p.wait()

if verbose:
Expand All @@ -23,7 +26,10 @@ def run(cmd, verbose=False, **kwargs):
def spawn(cmd, verbose=False, **kwargs):
if verbose:
print " [r] Waiting for %r" % (cmd,)
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
p = subprocess.Popen(cmd.split(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
**kwargs)
time.sleep(0.4)
return p

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

tests = {
'tut1': (gen('send'), gen('receive', java='Recv'), 'Hello World!'),
'tut2': (gen('new_task', arg='xxxxxx'), gen('worker'), 'xxxxxx'),
'tut3': (gen('emit_log', arg='123456'), gen('receive_logs'), '123456'),
'tut2': (gen('new_task', arg='%(arg)s'), gen('worker'), '%(arg)s'),
'tut3': (gen('emit_log', arg='%(arg)s'), gen('receive_logs'), '%(arg)s'),
}


verbose = len(sys.argv) > 1
errors = 0

for test in sorted(tests.keys()):
(send_progs, recv_progs, mask) = tests[test]
for scwd, scmd in send_progs:
for rcwd, rcmd in recv_progs:
(send_progs, recv_progs, output_mask) = tests[test]
for scwd, send_cmd in send_progs:
for rcwd, recv_cmd in recv_progs:
ctx = {
'arg': 'rand_%s' % (random.randint(1,100),)
}
rcmd = recv_cmd % ctx
scmd = send_cmd % ctx
mask = output_mask % ctx
p = spawn(rcmd, verbose=verbose, cwd=rcwd)
run(scmd, verbose=verbose, cwd=scwd)
if wait(p, mask, verbose=verbose):
print " [+] %s %-20s ok" % (test, scwd+'/'+rcwd)
else:
print " [!] %s %-20s FAILED %r %r" % (test, scwd+'/'+rcwd, rcmd, scmd)
print " [!] %s %-20s FAILED %r %r" % \
(test, scwd+'/'+rcwd, rcmd, scmd)
errors += 1

if errors:
print " [!] %s tests failed" % (errors,)

sys.exit(errors)

0 comments on commit 5fba979

Please sign in to comment.