Compare commits

..

10 Commits

Author SHA1 Message Date
Aleksej
20d4998c63
fix name of bot in testbot 2022-06-14 16:39:19 +02:00
Aleksej
36f4e9b324
fix false positives in testbot 2022-06-14 15:00:51 +02:00
Aleksej
f8bf2c62b0
fix typo in test.sh 2022-06-14 01:28:08 +02:00
Aleksej
405e7c21c3
add more info to test.sh 2022-06-14 01:21:53 +02:00
Aleksej
6e40fba236
more info on testbot 2022-06-14 01:11:35 +02:00
Aleksej
414174985b
add host and port in configuration 2022-06-14 01:05:39 +02:00
Aleksej
77abee6c5a
fix testbot typos 2022-06-13 23:36:08 +02:00
Aleksej
9aa08adef8
fix testbot misc 2022-06-13 23:34:16 +02:00
Aleksej
22c80eaf54
fix syntax errors in test.sh 2022-06-13 22:29:53 +02:00
Aleksej
19aa4e12d5
kill test bots after some time 2022-06-13 22:24:07 +02:00
5 changed files with 83 additions and 10 deletions

View File

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

View File

@ -1,5 +1,16 @@
#!/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
@ -15,12 +26,34 @@ 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
python3 ../xmppmirror &
echo "Running xmpp mirror bot"
python3 ../xmppmirror & XMPPMIRRORPID=$!
# Run xmpp test bot
python3 testbot
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
# Stop and remove containter
echo "Stopping and removing docker container"
docker stop xmppbot-test
docker rm xmppbot-test

View File

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

View File

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

View File

@ -59,6 +59,12 @@ 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)
@ -67,6 +73,9 @@ 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()