Compare commits

..

No commits in common. "20d4998c6374df859d219ff26231c2f7357bc02e" and "464d721af65a2fe36261fde933544e3627e38a8d" have entirely different histories.

5 changed files with 10 additions and 83 deletions

View File

@ -4,5 +4,3 @@ PASSWORD = bottestpassword
NICK = xmppbot
ROOM1 = testroom1@conference.localhost
ROOM2 = testroom2@conference.localhost
HOST = 127.0.0.1
PORT = 25222

View File

@ -1,16 +1,5 @@
#!/bin/bash
# Check if docker is installed
if ! command -v docker run &> /dev/null
then
echo "No docker detected. If you are running debian based system, you can install docker with"
echo "sudo apt install docker.io"
exit
fi
echo "Docker detected"
# Run ejabberd docker as a daemon
echo "Starting ejabberd docker container"
docker run --name xmppbot-test -d -p 25222:5222 ejabberd/ecs
# Wait few seconds for ejabberd to boot
@ -26,34 +15,12 @@ docker exec -it xmppbot-test bin/ejabberdctl create_room testroom1 conference.lo
docker exec -it xmppbot-test bin/ejabberdctl create_room testroom2 conference.localhost localhost
# Run xmpp mirror bot
echo "Running xmpp mirror bot"
python3 ../xmppmirror & XMPPMIRRORPID=$!
python3 ../xmppmirror &
# Run xmpp test bot
echo "Running test bot"
python3 testbot & TESTBOTPID=$!
# Wait for bots to connect
sleep 10
# Wait certain amount of time for every test message in the file
for i in $(cat testmsgs.txt); do sleep 5; done
# Kill bots
if ps -p $XMPPMIRRORPID > /dev/null
then
echo "Killing xmpp mirror bot"
kill $XMPPMIRRORPID
fi
if ps -p $TESTBOTPID > /dev/null
then
echo "Killing test bot"
kill $TESTBOTPID
fi
python3 testbot
# Stop and remove containter
echo "Stopping and removing docker container"
docker stop xmppbot-test
docker rm xmppbot-test

View File

@ -3,7 +3,6 @@
import argparse
import slixmpp
import configparser
import time
CONFIG_PATH = "./testconfig.ini"
@ -32,23 +31,14 @@ def allmsgsrecv():
for i in results2:
if i[2] == 0:
return False
return ret
# Print results and exit
def printandexit():
print("Results of test:")
print("Room1 -> Room2:")
for i in results1:
if i[2] == 0:
print(i[0] + " : Not recieved")
else:
print(i[0].rstrip() + " : " + str(round(i[2]-i[1],2)) + " secounds")
print("Room2 -> Room1:")
print(i[0].rstrip + " : " + str(round(i[2]-i[1],2)) + " secounds")
for i in results2:
if i[2] == 0:
print(i[0] + " : Not recieved")
else:
print(i[0].rstrip() + " : " + str(round(i[2]-i[1],2)) + " secounds")
print(i[0].rstrip + " : " + str(round(i[2]-i[1],2)) + " secounds")
exit()
def show_version():
@ -91,26 +81,19 @@ class MUCBot(slixmpp.ClientXMPP):
def muc_message(self, msg):
rtime=time.time()
if msg['mucnick'] == self.nick:
return
rcpt=msg['from'].bare
body="%(body)s" % msg
unknownmsg = True
if self.room1 in str(msg['from']):
for i in results2:
if "admin: " + i[0] == body:
if i[0] == body:
i[2] = rtime
unknownmsg = False
if self.room2 in str(msg['from']):
for i in results1:
if "admin: " + i[0] == body:
if i[0] == body:
i[2] = rtime
unknownmsg = False
if unknownmsg:
print("Unknown message recieved: " + body)
if allmsgsrecv() is True:
if allmsgsrecv:
printandexit()
@ -131,13 +114,6 @@ if __name__ == '__main__':
NICK = config.get('credentials', 'NICK')
ROOM1 = config.get('credentials', 'ROOM1')
ROOM2 = config.get('credentials', 'ROOM2')
HOST = None
PORT = 5222
if "host" in config.options('credentials'):
HOST = config.get('credentials', 'HOST')
if "port" in config.options('credentials'):
PORT = config.get('credentials', 'PORT')
xmpp = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2)
@ -146,9 +122,6 @@ if __name__ == '__main__':
xmpp.register_plugin('xep_0199') # XMPP Ping
# Connect to the XMPP server and start processing XMPP stanzas.
if HOST != None:
xmpp.connect(address=(HOST,int(PORT)))
else:
xmpp.connect()
xmpp.connect(address=("localhost",25222))
xmpp.process(forever=False)

View File

@ -4,5 +4,3 @@ PASSWORD = admintestpassword
NICK = admin
ROOM1 = testroom1@conference.localhost
ROOM2 = testroom2@conference.localhost
HOST = 127.0.0.1
PORT = 25222

View File

@ -59,12 +59,6 @@ if __name__ == '__main__':
NICK = config.get('credentials', 'NICK')
ROOM1 = config.get('credentials', 'ROOM1')
ROOM2 = config.get('credentials', 'ROOM2')
HOST = None
PORT = 5222
if "host" in config.options('credentials'):
HOST = config.get('credentials', 'HOST')
if "port" in config.options('credentials'):
PORT = config.get('credentials', 'PORT')
xmpp = MUCBot(JID, PASSWORD, NICK, ROOM1, ROOM2)
@ -73,9 +67,6 @@ if __name__ == '__main__':
xmpp.register_plugin('xep_0199') # XMPP Ping
# Connect to the XMPP server and start processing XMPP stanzas.
if HOST != None:
xmpp.connect(address=(HOST,int(PORT)))
else:
xmpp.connect()
xmpp.process()