Skip to content

Commit

Permalink
Updated script to remove global lock and modified both unit and accep…
Browse files Browse the repository at this point in the history
…tance tests accordingly. Added new atest to test new code. MarketSquare#41
  • Loading branch information
tatipamu committed Dec 9, 2015
1 parent b0ff606 commit b9a62af
Show file tree
Hide file tree
Showing 13 changed files with 387 additions and 147 deletions.
20 changes: 19 additions & 1 deletion atest/Protocols.robot
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,25 @@ Define protocol, start tcp server and two clients
Accept connection alias=Connection1
connect ${SERVER} ${SERVER PORT} name=ExampleClient2
Accept connection alias=Connection2


Define protocol, start tcp server and four clients
[Arguments] ${protocol}=
Define example protocol
Start TCP server ${SERVER} ${SERVER PORT} name=ExampleServer protocol=${protocol}
Start TCP client name=ExampleClient1 protocol=${protocol}
Start TCP client name=ExampleClient2 protocol=${protocol}
Start TCP client name=ExampleClient3 protocol=${protocol}
Start TCP client name=ExampleClient4 protocol=${protocol}
connect ${SERVER} ${SERVER PORT} name=ExampleClient1
Accept connection alias=Connection1
connect ${SERVER} ${SERVER PORT} name=ExampleClient2
Accept connection alias=Connection2
connect ${SERVER} ${SERVER PORT} name=ExampleClient3
Accept connection alias=Connection3
connect ${SERVER} ${SERVER PORT} name=ExampleClient4
Accept connection alias=Connection4


Setup UDP server and client
[Arguments] ${protocol}=
Start udp server ${SERVER} ${SERVER PORT} name=ExampleServer protocol=${protocol} timeout=1
Expand Down
38 changes: 34 additions & 4 deletions atest/asynchronous_messages/asynchronous_msg.robot
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,32 @@ Register an auto reply to work on background
Wait until keyword succeeds 2s 0.1s Handler should have been called with '1' sample messages
Message cache should be empty
Timeout at background
[timeout] 3s
[timeout] 4s
[Setup] Setup protocol, one client, background server, and define templates Send 10 messages every 0.5 seconds
Load Template sample
Reset received messages
Set client handler my_handler.respond_to_sample header_filter=messageType
Load Template another
Run keyword and expect error Timeout 0.6* Client receives message header_filter=messageType timeout=0.6
Run keyword and expect error Timeout* Client receives message header_filter=messageType timeout=0.6
[Teardown] Get background results and reset
Two clients handling same message asynchronously without any effect from main message
[Setup] Setup protocol, two clients, background server, and define templates Send 10 messages every 0.5 seconds using given connection
Load Template sample
Reset received messages
Set client handler my_handler.respond_to_sample name=client1 header_filter=messageType
Set client handler my_handler.respond_to_sample name=client2 header_filter=messageType
Load Template sample response
Client receives message name=client1 header_filter=messageType timeout=5
sleep 2
[Teardown] Get background results and reset

*** Variables ***
${SOURCEDIR}= ${CURDIR}${/}..${/}..${/}src
${BACKGROUND FILE}= ${CURDIR}${/}background_server.robot

*** Keywords ***


Send receive another
Load template another
client sends message
Expand All @@ -96,11 +108,29 @@ Setup protocol, one client, background server, and define templates
Start background process ${background operation}
Start TCP client 127.0.0.1 45555 name=client protocol=Example
Wait Until Created ${SIGNAL FILE} timeout=10 seconds
sleep 0.1s # Just to make sure we dont get inbetween keywordcalls
sleep 0.2s # Just to make sure we dont get inbetween keywordcalls
Connect 127.0.0.1 ${SERVER PORT}

Setup protocol, two clients, background server, and define templates
[Arguments] ${background operation}
Define Example protocol
Define templates
Remove File ${SIGNAL FILE}
Start background process ${background operation}
sleep 0.1
Wait Until Created ${SIGNAL FILE} timeout=10 seconds
Start TCP client 127.0.0.1 48888 name=client1 protocol=Example
Connect 127.0.0.1 ${SERVER PORT}
Start TCP client 127.0.0.1 47777 name=client2 protocol=Example
Connect 127.0.0.1 ${SERVER PORT}

Setup protocol, server, two clients, and define templates
Define protocol, start tcp server and two clients protocol=Example
Define templates

Setup protocol, server, four clients, and define templates
Define protocol, start tcp server and four clients protocol=Example
Define templates
Setup protocol, nodes, and define templates
Setup protocol, TCP server, and client
Define Templates
Expand Down Expand Up @@ -129,4 +159,4 @@ Start background process
${process}= Start process python -m robot.run --test ${name} --loglevel DEBUG
... --variable BACKGROUND:True --variable PORT:${SERVER PORT} --pythonpath ${SOURCEDIR}
... --outputdir ${TEMPDIR} ${BACKGROUND FILE}
[Return] ${process}
[Return] ${process}
52 changes: 46 additions & 6 deletions atest/asynchronous_messages/background_server.robot
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Loop on background
Send 10 messages every 0.5 seconds
Run keyword if ${BACKGROUND} Send 10 messages every 0.5 seconds
... ELSE Set test documentation Skipped because not run on background.

Send 10 messages every 0.5 seconds using given connection
Run keyword if ${BACKGROUND} Send 10 messages every 0.5 seconds using given connection
... ELSE Set test documentation Skipped because not run on background.
*** Keywords ***
Serve on loop
Setup connection
Expand All @@ -35,25 +37,25 @@ Serve
Receive another
Send sample receive sample
Send another
Sleep 5
Sleep 10

Send 10 messages every 0.5 seconds
Setup connection
:FOR ${i} IN RANGE 10
\ Send sample receive sample
\ Sleep 0.5

Send sample receive sample
Send sample
Receive sample response

Setup connection
Define example protocol
Define Templates
Start TCP server 127.0.0.1 ${PORT} name=ExampleServer protocol=Example
Touch ${SIGNAL FILE}
Accept connection

Send sample receive sample
Send sample
Receive sample response

Send [arguments] ${message}
Load template ${message}
Server sends message
Expand All @@ -62,4 +64,42 @@ Receive [arguments] ${message}
Load template ${message}
Server receives message header_filter=messageType

Setup connection with two clients
Define example protocol
Define Templates
Start TCP server 127.0.0.1 ${PORT} name=ExampleServer protocol=Example
Touch ${SIGNAL FILE}
Accept connection alias=Connection1
Accept connection alias=Connection2

Send 10 messages every 0.5 seconds using given connection
Setup connection with two clients
log Started handling ten messages for client1
:FOR ${i} IN RANGE 10
\ Send sample and receive sample using connection1
\ Sleep 0.2
log Successfully handled ten messages for client1
log Started handling ten messages for client2
:FOR ${i} IN RANGE 10
\ Send sample and receive sample using connection2
\ Sleep 0.2
log Successfully handled ten messages for client1
load template sample response
server sends message connection=Connection1

Send sample and receive sample using connection1
Send using given connection sample Connection1
Receive using given connection sample response Connection1

Send sample and receive sample using connection2
Send using given connection sample Connection2
run keyword and continue on failure Receive using given connection sample response Connection1
run keyword and continue on failure Receive using given connection sample response Connection2

Send using given connection [arguments] ${message} ${connection}
Load template ${message}
Server sends message connection=${connection}

Receive using given connection [arguments] ${message} ${connection}
Load template ${message}
Server receives message alias=${connection} header_filter=messageType timeout=0.1
49 changes: 20 additions & 29 deletions atest/asynchronous_messages/my_handler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from Rammbock import logger
import sys


RECEIVED_MESSAGES = []
SERVER_SENT = {'sample': 0,
'another': 0}
SERVER_SENT = {'sample': 0, 'another': 0}


def handle_sample(rammbock, msg):
Expand All @@ -16,49 +16,40 @@ def reset_received_messages():


def respond_to_sample(rammbock, msg, client):
RECEIVED_MESSAGES.append(msg)
sys.__stdout__.write("Sending 11111 DWR '%s'" % client.name)
foo = "adding Extra Variable to replicate ArgCount bug"
bar = "adding Extra Variable to replicate ArgCount bug"
RECEIVED_MESSAGES.append(msg)
#rammbock.save_template("__backup_template")
try:
#rammbock.load_template("sample response")
template = rammbock.get_template('sample response')[0]
rammbock.client_sends_given_message(template,'name=%s' % client.name)
finally:
pass
#rammbock.load_template("__backup_template")
template, fields, headers = rammbock.get_template('sample response')
rammbock.client_sends_given_message(template, fields, headers, 'name=%s' % client.name)


def respond_to_sample2(rammbock, msg, client):
RECEIVED_MESSAGES.append(msg)
sys.__stdout__.write("Sending DWR '%s'" % client.name)
foo = "adding Extra Variable to replicate ArgCount bug"
bar = "adding Extra Variable to replicate ArgCount bug"
template, fields, headers = rammbock.get_template('sample response')
rammbock.client_sends_given_message(template, fields, headers, 'name=%s' % client.name)

def server_respond_to_another_max_100(rammbock, msg, server, connection):
RECEIVED_MESSAGES.append(msg)
if SERVER_SENT['another'] < 100:
SERVER_SENT['another'] = SERVER_SENT['another'] + 1
#rammbock.save_template("__backup_template")
try:
#rammbock.load_template("another")
template = rammbock.get_template('another')[0]
rammbock.server_sends_given_message(template, 'name=%s' % server.name, 'connection=%s' % connection.name)
finally:
pass
# rammbock.load_template("__backup_template")
template, fields, headers = rammbock.get_template('another')
rammbock.server_sends_given_message(template, fields, headers, 'name=%s' % server.name, 'connection=%s' % connection.name)
else:
pass
#logger.("Reached 100 in another")
logger.warn("Reached 100 in another")


def server_respond_to_sample_response_max_100(rammbock, msg):
RECEIVED_MESSAGES.append(msg)
if SERVER_SENT['sample'] < 100:
SERVER_SENT['sample'] = SERVER_SENT['sample'] + 1
rammbock.save_template("__backup_template")
try:
rammbock.load_template("sample")
rammbock.server_sends_message()
finally:
rammbock.load_template("__backup_template")
template, fields, headers = rammbock.get_template('sample')
rammbock.server_sends_given_message(template, fields, headers)
else:
pass
#logger.warn("Reached 100 in sample")
logger.warn("Reached 100 in sample")


def get_rcvd_msg():
Expand Down
Loading

0 comments on commit b9a62af

Please sign in to comment.