Skip to content

Commit a492478

Browse files
committed
Automate testing.
1 parent b4c0b9e commit a492478

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

Makefile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Ignore this file, go straight to the directory with your language of
2+
# choice and read the readme there.
3+
#
4+
# This makefile is for testing only. It's intended to install
5+
# dependencies for all source code languages, which is an overkill for
6+
# the great majority of users.
7+
#
8+
9+
all:
10+
@echo "Review README in the directory with your langage of choice."
11+
12+
13+
# Test all combinations of languages
14+
test: dotnet/.ok erlang/.ok java/.ok python/.ok php/.ok ruby/.ok
15+
python test.py
16+
17+
R=http://www.rabbitmq.com/releases
18+
dotnet/.ok:
19+
(cd dotnet && \
20+
mkdir lib && \
21+
cd lib && \
22+
wget $(R)/rabbitmq-dotnet-client/v2.4.1/rabbitmq-dotnet-client-2.4.1-dotnet-3.0.zip && \
23+
unzip rabbitmq-dotnet-client-2.4.1-dotnet-3.0.zip && \
24+
for f in *.cs; do \
25+
gmcs -r:lib/bin/RabbitMQ.Client.dll $$f; \
26+
done && \
27+
touch .ok)
28+
29+
30+
erlang/.ok:
31+
(cd erlang && \
32+
wget $(R)/plugins/v2.5.0/rabbit_common-2.5.0.ez && \
33+
unzip rabbit_common-2.5.0.ez && \
34+
ln -s rabbit_common-2.5.0 rabbit_common && \
35+
wget $(R)/releases/plugins/v2.5.0/amqp_client-2.5.0.ez && \
36+
unzip amqp_client-2.5.0.ez && \
37+
ln -s amqp_client-2.5.0 amqp_client && \
38+
touch .ok)
39+
40+
java/.ok:
41+
(cd java && \
42+
wget $(R)/rabbitmq-java-client/v2.4.1/rabbitmq-java-client-bin-2.4.1.zip && \
43+
unzip rabbitmq-java-client-bin-2.4.1.zip && \
44+
cp rabbitmq-java-client-bin-2.4.1/*.jar . && \
45+
javac -cp rabbitmq-client.jar *.java && \
46+
touch .ok)
47+
48+
python/.ok:
49+
(cd python && \
50+
virtualenv venv && \
51+
./venv/bin/pip install pika==0.9.5 && \
52+
touch .ok)
53+
54+
php/.ok:
55+
(cd php && \
56+
git clone http://github.com/tnc/php-amqplib.git lib/php-amqplib && \
57+
touch .ok)
58+
59+
ruby/.ok:
60+
(cd ruby && \
61+
GEM_HOME=gems/gems RUBYLIB=gems/lib gem1.8 install amqp --pre --version "= 0.8.0.rc12" && \
62+
touch .ok)

test.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python
2+
import time
3+
import re
4+
import subprocess
5+
import signal
6+
import sys
7+
8+
def run(cmd, verbose=False, **kwargs):
9+
if verbose:
10+
print " [s] Running %r" % (cmd,)
11+
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, **kwargs)
12+
p.wait()
13+
14+
if verbose:
15+
for line in p.stdout:
16+
line = p.stdout.readline().strip()
17+
if line:
18+
print ' [s] %s' % (line,)
19+
print " [s] Done"
20+
time.sleep(0.1)
21+
22+
23+
def spawn(cmd, verbose=False, **kwargs):
24+
if verbose:
25+
print " [r] Waiting for %r" % (cmd,)
26+
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
27+
time.sleep(0.4)
28+
return p
29+
30+
def wait(p, match, verbose=False):
31+
p.send_signal(signal.SIGINT)
32+
p.wait()
33+
r = False
34+
for line in p.stdout:
35+
if re.search(match, line):
36+
r = True
37+
if verbose:
38+
print " [r] %s" % (line.strip(),)
39+
if verbose:
40+
print " [r] Done"
41+
return r
42+
43+
44+
45+
def gen(prog, arg="", **kwargs):
46+
Prog = ''.join([w.capitalize() for w in prog.split('_')])
47+
ctx = {
48+
'python': kwargs.get('python', prog),
49+
'erlang': kwargs.get('erlang', prog),
50+
'java': kwargs.get('java', Prog),
51+
'dotnet': kwargs.get('dotnet', Prog),
52+
'ruby': kwargs.get('ruby', prog),
53+
'php': kwargs.get('php', prog),
54+
'arg': arg,
55+
}
56+
return [
57+
('python', './venv/bin/python %(python)s.py %(arg)s' % ctx),
58+
('erlang', './%(python)s.erl %(arg)s' % ctx),
59+
('java', 'java -cp .:commons-io-1.2.jar:commons-cli-1.1.jar:'
60+
'rabbitmq-client.jar %(java)s %(arg)s' % ctx),
61+
('dotnet', 'env MONO_PATH=lib/bin mono %(dotnet)s.exe %(arg)s' % ctx),
62+
# ('ruby', 'env RUBYOPT=-rubygems GEM_HOME=gems/gems RUBYLIB=gems/lib '
63+
# 'ruby1.8 %(ruby)s.rb %(arg)s' % ctx),
64+
('php', 'php %(php)s.php %(arg)s' % ctx),
65+
]
66+
67+
tests = {
68+
'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'),
71+
}
72+
73+
74+
verbose = len(sys.argv) > 1
75+
76+
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:
80+
p = spawn(rcmd, verbose=verbose, cwd=rcwd)
81+
run(scmd, verbose=verbose, cwd=scwd)
82+
if wait(p, mask, verbose=verbose):
83+
print " [+] %s %-20s ok" % (test, scwd+'/'+rcwd)
84+
else:
85+
print " [!] %s %-20s FAILED %r %r" % (test, scwd+'/'+rcwd, rcmd, scmd)

0 commit comments

Comments
 (0)