Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
executable file 108 lines (92 sloc) 3.12 KB
#!/usr/bin/env python
import time
import random
import re
import subprocess
import signal
import sys
import os
def run(cmd, verbose=False, **kwargs):
if verbose:
print " [s] Running %r" % (cmd,)
p = subprocess.Popen(cmd.split(),
if verbose:
for line in p.stdout:
line = p.stdout.readline().strip()
if line:
print ' [s] %s' % (line,)
print " [s] Done"
def spawn(cmd, verbose=False, **kwargs):
if verbose:
print " [r] Waiting for %r" % (cmd,)
p = subprocess.Popen(cmd.split(),
return p
def wait(p, match, verbose=False):
os.kill(, signal.SIGINT)
r = False
for line in p.stdout:
if, line):
r = True
if verbose:
print " [r] %s" % (line.strip(),)
if verbose:
print " [r] Done"
return r
def gen(prog, arg="", **kwargs):
Prog = ''.join([w.capitalize() for w in prog.split('_')])
ctx = {
'python': kwargs.get('python', prog),
'erlang': kwargs.get('erlang', prog),
'java': kwargs.get('java', Prog),
'dotnet': kwargs.get('dotnet', Prog),
'ruby': kwargs.get('ruby', prog),
'php': kwargs.get('php', prog),
'arg': arg,
return [
('python', './venv/bin/python %(python) %(arg)s' % ctx),
('erlang', './%(python)s.erl %(arg)s' % ctx),
('java', 'java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:'
'rabbitmq-client.jar %(java)s %(arg)s' % ctx),
('dotnet', 'env MONO_PATH=lib/bin mono %(dotnet)s.exe %(arg)s' % ctx),
('ruby', 'env RUBYOPT=-rubygems GEM_HOME=gems/gems RUBYLIB=gems/lib '
'ruby1.8 %(ruby)s.rb %(arg)s' % ctx),
('php', 'php %(php)s.php %(arg)s' % ctx),
tests = {
'tut1': (gen('send'), gen('receive', java='Recv'), 'Hello World!'),
'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, 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)
print " [!] %s %-20s FAILED %r %r" % \
(test, scwd+'/'+rcwd, rcmd, scmd)
errors += 1
if errors:
print " [!] %s tests failed" % (errors,)
Jump to Line
Something went wrong with that request. Please try again.