Skip to content

Commit

Permalink
Refactored the code to remove global lock and updated both unit and a…
Browse files Browse the repository at this point in the history
…cceptance tests accordingly. MarketSquare#41
  • Loading branch information
vivektatipamula committed Jan 15, 2016
1 parent 3a7faf9 commit 54688fb
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 342 deletions.
20 changes: 1 addition & 19 deletions atest/Protocols.robot
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,7 @@ 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
45 changes: 35 additions & 10 deletions atest/asynchronous_messages/asynchronous_msg.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*** Settings ***
Library Process
Library Collections
Resource async_resources.robot
Test Setup Setup protocol, nodes, and define templates
Test teardown Teardown rammbock and increment port numbers
Expand Down Expand Up @@ -74,20 +75,48 @@ Timeout at background
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
[Documentation] This test is rather slow will handle multiple messages related to two clients at a time, so run with --exclude slow to skip this.
[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
Client receives message name=client2 header_filter=messageType timeout=10
Client receives message name=client1 header_filter=messageType timeout=10
Client receives message name=client2 header_filter=messageType timeout=10
Client receives message name=client1 header_filter=messageType timeout=10
Client receives message name=client2 header_filter=messageType timeout=10
sleep 2
[Teardown] Get background results and reset
Get message using get message template keyword and perform send and receive operations with validation
[Setup] Setup protocol, server, two clients, and define templates
${message_and_fields}= Get Message Template sample
client sends given message ${message_and_fields} name=ExampleClient1
client sends given message ${message_and_fields} name=ExampleClient1
${message_and_fields}= Get Message Template sample response
Run Keyword And Expect Error timeout: timed out server receives given message ${message_and_fields} alias=Connection1 header_filter=messageType timeout=0.2
${message_and_fields}= Get Message Template sample
Set To Dictionary ${message_and_fields[1]} foo 12
Run Keyword And Expect Error Value of field foo does not match 0x0001!=12 server receives given message ${message_and_fields} alias=Connection1 header_filter=messageType
${message_and_fields}= Get Message Template sample
server receives given message ${message_and_fields} alias=Connection1 header_filter=messageType
${message_and_fields}= Get Message Template sample response
server sends given message ${message_and_fields} connection=Connection2
server sends given message ${message_and_fields} connection=Connection2
${message_and_fields}= Get Message Template sample
Run Keyword And Expect Error timeout: timed out client receives given message ${message_and_fields} name=ExampleClient2 header_filter=messageType timeout=0.2
${message_and_fields}= Get Message Template sample response
Set To Dictionary ${message_and_fields[1]} bar 12
Run Keyword And Expect Error Value of field bar does not match 0x0064!=12 client receives given message ${message_and_fields} name=ExampleClient2 header_filter=messageType
${message_and_fields}= Get Message Template sample response
client receives given message ${message_and_fields} name=ExampleClient2 header_filter=messageType


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

${PORT2}= 44488
*** Keywords ***


Expand Down Expand Up @@ -118,19 +147,15 @@ Setup protocol, two clients, background server, and define templates
Remove File ${SIGNAL FILE}
Start background process ${background operation}
sleep 0.1
Start TCP client 127.0.0.1 ${CLIENT 1 PORT} name=client1 protocol=Example
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}
Connect 127.0.0.1 ${PORT2}
Start TCP client 127.0.0.1 ${CLIENT 2 PORT} name=client2 protocol=Example
Connect 127.0.0.1 ${PORT2}

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
50 changes: 30 additions & 20 deletions atest/asynchronous_messages/background_server.robot
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Force tags background
*** Variables ***
${BACKGROUND}= ${False}
${PORT}= 44455
${PORT2}= 44488

*** Test Cases ***
Serve on background
Expand Down Expand Up @@ -67,39 +68,48 @@ Receive [arguments] ${message}
Setup connection with two clients
Define example protocol
Define Templates
Start TCP server 127.0.0.1 ${PORT} name=ExampleServer protocol=Example
Start TCP server 127.0.0.1 ${PORT2} 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
load template sample response
server sends message connection=Connection2
: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
\ Sleep 0.01
load template sample response
server sends message connection=Connection1
:FOR ${i} IN RANGE 10
\ Send sample and receive sample using connection2
\ Sleep 0.01
load template sample response
server sends message connection=Connection2
:FOR ${i} IN RANGE 10
\ Send sample and receive sample using connection2
\ Sleep 0.2
log Successfully handled ten messages for client1
\ Sleep 0.01
load template sample response
server sends message connection=Connection1

:FOR ${i} IN RANGE 10
\ Send sample and receive sample using connection1
\ Sleep 0.01
load template sample response
server sends message connection=Connection2

Send sample and receive sample using connection1
Send using given connection sample Connection1
Receive using given connection sample response Connection1
Send message using given connection sample Connection1
Receive message 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}
Send message using given connection sample Connection2
Receive message using given connection sample response Connection2

Receive using given connection [arguments] ${message} ${connection}
Load template ${message}
Server receives message alias=${connection} header_filter=messageType timeout=0.1
Send message using given connection [arguments] ${message} ${connection}
${data}= get message template ${message}
Server sends given message ${data} connection=${connection}

Receive message using given connection [arguments] ${message} ${connection}
${data}= get message template ${message}
Server receives given message ${data} alias=${connection} header_filter=messageType
21 changes: 6 additions & 15 deletions atest/asynchronous_messages/my_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,18 @@ 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"
template, fields, headers = rammbock.get_template('sample response')
rammbock.client_sends_given_message(template, fields, headers, 'name=%s' % client.name)
message_template = rammbock.get_message_template('sample response')
rammbock.client_sends_given_message(message_template, 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
template, fields, headers = rammbock.get_template('another')
rammbock.server_sends_given_message(template, fields, headers, 'name=%s' % server.name, 'connection=%s' % connection.name)
message_template = rammbock.get_message_template('another')
rammbock.server_sends_given_message(message_template, server.name, connection.name)
else:
logger.warn("Reached 100 in another")

Expand All @@ -46,8 +37,8 @@ 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
template, fields, headers = rammbock.get_template('sample')
rammbock.server_sends_given_message(template, fields, headers)
message_template = rammbock.get_message_template('sample')
rammbock.server_sends_given_message(message_template)
else:
logger.warn("Reached 100 in sample")

Expand Down
Loading

0 comments on commit 54688fb

Please sign in to comment.