Changeset - 4ecee51f2b46
[Not reviewed]
1 1 2
Jan Kaluza - 10 years ago 2015-12-16 09:40:01
jkaluza@redhat.com
Better test framework and output :)
4 files changed with 128 insertions and 96 deletions:
0 comments (0 inline, 0 general)
.travis.yml
Show inline comments
 
@@ -13,6 +13,6 @@ before_script:
 
          - sudo apt-get install -y --force-yes ngircd python-sleekxmpp libswiften-dev libprotobuf-dev protobuf-compiler pidgin-dev liblog4cxx10-dev libpopt-dev libboost-dev libboost-signals-dev libboost-system-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev libboost-date-time-dev libcppunit-dev libcommuni-dev
 
install: "pip install --user sleekxmpp"
 
script:
 
          - cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON . && make && ./src/libtransport_test && make spectrum2 && cd ./spectrum/src/tests && python -V && python irc_test.py
 
          - cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON . && make && ./src/libtransport_test && make spectrum2 && cd ./spectrum/src/tests && python -V && python start.py
 
notifications:
 
  slack: spectrum2:CIlYHtxGMAaxs3qVHfwBzCuy
spectrum/src/tests/irc_test.py
Show inline comments
 
deleted file
spectrum/src/tests/muc_echo.py
Show inline comments
 
new file 100644
 
import optparse
 
import sys
 
import time
 
import subprocess
 
import os
 

	
 
import sleekxmpp
 

	
 

	
 
class Responder(sleekxmpp.ClientXMPP):
 
	def __init__(self, jid, password, room, nick):
 
		sleekxmpp.ClientXMPP.__init__(self, jid, password)
 
		self.room = room
 
		self.nick = nick
 
		self.add_event_handler("session_start", self.start)
 
		self.add_event_handler("groupchat_message", self.muc_message)
 

	
 
		self.tests = {}
 

	
 
	def muc_message(self, msg):
 
		if msg['mucnick'] != self.nick:
 
			self.send_message(mto=msg['from'].bare,
 
							mbody="echo %s" % msg['body'],
 
							mtype='groupchat')
 

	
 
	def start(self, event):
 
		self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True)
 

	
 
class Client(sleekxmpp.ClientXMPP):
 
	def __init__(self, jid, password, room, nick):
 
		sleekxmpp.ClientXMPP.__init__(self, jid, password)
 
		self.room = room
 
		self.nick = nick
 
		self.add_event_handler("session_start", self.start)
 
		self.add_event_handler("groupchat_message", self.muc_message)
 
		self.finished = False
 

	
 
		self.tests = {}
 
		self.tests["echo_received"] = ["libcommuni: Send and receive messages", False]
 

	
 
	def muc_message(self, msg):
 
		if msg['mucnick'] != self.nick:
 
			if msg['body'] == "echo abc":
 
				self.tests["echo_received"][1] = True
 
				self.finished = True
 

	
 
	def start(self, event):
 
		self.getRoster()
 
		self.sendPresence()
 
		self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True)
 
		self.send_message(mto=self.room, mbody="abc", mtype='groupchat')
spectrum/src/tests/start.py
Show inline comments
 
new file 100644
 
import optparse
 
import sys
 
import time
 
import subprocess
 
import os
 

	
 
import sleekxmpp
 
import imp
 

	
 
def single_test(Client, Responder):
 
	os.system("../spectrum2 -n ./irc_test.cfg > spectrum2.log &")
 
	os.system("ngircd -f ngircd.conf &")
 
	time.sleep(1)
 
	responder = Responder("responder@localhost", "password", "#channel@localhost", "responder")
 
	responder.register_plugin('xep_0030')  # Service Discovery
 
	responder.register_plugin('xep_0045')  # Multi-User Chat
 
	responder.register_plugin('xep_0199')  # XMPP Ping
 
	responder['feature_mechanisms'].unencrypted_plain = True
 

	
 
	if responder.connect():
 
		responder.process(block=False)
 
	else:
 
		print "connect() failed"
 
		sys.exit(1)
 

	
 
	client = Client("client@localhost", "password", "#channel@localhost", "client")
 
	client.register_plugin('xep_0030')  # Service Discovery
 
	client.register_plugin('xep_0045')  # Multi-User Chat
 
	client.register_plugin('xep_0199')  # XMPP Ping
 
	client['feature_mechanisms'].unencrypted_plain = True
 

	
 
	time.sleep(2)
 

	
 
	if client.connect():
 
		client.process(block=False)
 
	else:
 
		print "connect() failed"
 
		sys.exit(1)
 

	
 
	max_time = 60
 
	while not client.finished and max_time > 0:
 
		time.sleep(1)
 
		max_time -= 1
 
	client.disconnect()
 
	responder.disconnect()
 

	
 
	os.system("killall spectrum2")
 
	os.system("killall ngircd")
 
	os.system("killall spectrum2_libcommuni_backend 2>/dev/null")
 

	
 
	ret = True
 
	for v in client.tests.values():
 
		if v[1]:
 
			print v[0] + ": PASSED"
 
		else:
 
			print v[0] + ": FAILED"
 
			ret = False
 

	
 
	if not ret:
 
		os.system("cat spectrum2.log")
 

	
 
	return ret
 

	
 
exitcode = 0
 
for f in os.listdir("."):
 
	if not f.endswith(".py") or f == "start.py":
 
		continue
 

	
 
	print "Starting " + f + " test ..."
 
	test = imp.load_source('test', './' + f)
 
	ret = single_test(test.Client, test.Responder)
 
	if not ret:
 
		exitcode = -1
 

	
 
sys.exit(exitcode)
 

	
0 comments (0 inline, 0 general)