Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the code to handle the asynchronous messages for all clients without any impact of main flow. #41 #58

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atest/Protocols.robot
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ Close client '${client_original}' and switch to client '${alternate_client}'

Close server '${original_server}' and switch to server '${alternate_server}'
Close Server name=${original_server}
Switch Server name=${alternate_server}
Switch Server name=${alternate_server}
65 changes: 60 additions & 5 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 @@ -65,20 +66,60 @@ 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
[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=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 ***


Send receive another
Load template another
client sends message
Expand All @@ -96,8 +137,22 @@ 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
Start TCP client 127.0.0.1 ${CLIENT 1 PORT} name=client1 protocol=Example
Wait Until Created ${SIGNAL FILE} timeout=10 seconds
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
Expand Down Expand Up @@ -129,4 +184,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}
62 changes: 56 additions & 6 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 All @@ -19,7 +20,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 +38,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 +65,51 @@ 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 ${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
load template sample response
server sends message connection=Connection2
:FOR ${i} IN RANGE 10
\ Send sample and receive sample using connection1
\ 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.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 message using given connection sample Connection1
Receive message using given connection sample response Connection1

Send sample and receive sample using connection2
Send message using given connection sample Connection2
Receive message using given connection sample response Connection2

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
30 changes: 9 additions & 21 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,27 +16,19 @@ def reset_received_messages():


def respond_to_sample(rammbock, msg, client):
RECEIVED_MESSAGES.append(msg)
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")
rammbock.client_sends_message('name=%s' % client.name)
finally:
rammbock.load_template("__backup_template")
message_template = rammbock.get_message_template('sample response')
rammbock.client_sends_given_message(message_template, 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")
rammbock.server_sends_message('name=%s' % server.name, 'connection=%s' % connection.name)
finally:
rammbock.load_template("__backup_template")
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 @@ -45,12 +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
rammbock.save_template("__backup_template")
try:
rammbock.load_template("sample")
rammbock.server_sends_message()
finally:
rammbock.load_template("__backup_template")
message_template = rammbock.get_message_template('sample')
rammbock.server_sends_given_message(message_template)
else:
logger.warn("Reached 100 in sample")

Expand Down
Loading