Testing a chat example - nsvir/logTest GitHub Wiki
In this example, we will get you through this live test example.
To simplify our example we will strip the log of the timestamps.
The log
Client log | Server log |
---|---|
Connecting to localhost on port 7520... |
Server Listening on port : 7520 |
Connected to localhost/127.0.0.1:7520 |
Connected to /127.0.0.1:60174 |
[ Sent ] Hello |
[ Received ] Hello |
[ Received ] Hello |
[ noise log ] |
[ Sent ] ACK |
[ noise log ] |
[ Received ] DATA1 |
[ noise log ] |
[ Sent ] ACK |
[ noise log ] |
[ Sent ] DATA2 |
[ Sent ] Hello |
[ Received ] ACK |
[ Received ] ACK |
[ Sent ] Disconnecting |
[ Sent ] DATA1 |
[ Received ] ACK |
[ Received ] ACK |
[ Disconnected ] |
[ Received ] DATA2 |
[ noise log ] |
[ Sent ] ACK |
[ noise log ] |
[ Received ] Disconnecting |
[ noise log ] |
[ Sent ] ACK |
[ noise log ] |
[ Disconnected ] |
The test file
- Testing a simple chat scenario :
def testSimpleChatScenario():
scenario("Testing Simple chat application")
client = Agent("Client", "client.log")
server = Agent("Server" ,"server.log")
connect(client, server)#Start connection session (semantic operation)
_send(server, "DATA1", client)
_send(client, "DATA2", server)
disconnect()#End the connection session
#verify() unnecessary, I prefer to omit this, and do it as a hooker after each scenario
- Defining the connect method (semantic method):
def connect(client, server):#override
_send(client, "Hello", server)
_send(server, "Hello", client)
_send(client, "ACK", server)
- Defining the disconnect method (semantic method):
def disconnect(client, server):#override
_send(client, "Disconnecting", server)
_send(server, "ACK", client)
server.expect("Disconnected")
client.expect("Disconnected")
- If you are wondering what are the main bricks the developer has to use, well they are
send
andreceive
:
def _send(a1, message, a2):
behavior("Message: %s, is sent" % message)#define a semantic to the added behavior
a1.send(message, a2);#if error: message from n1 to n2 failed to be sent
a2.receive(message, a1, 2000);
- To parse the log, The developer must define
send
as an action:
def send(message):#override: define a semantic send
expect("[ Sent ] " + message)#if error, show: Message $message was not sent between $self.source and $self.target.
- The developer must define
receive
as an event :
def receive(message, timeout):#override: define a semantic receive
wait("[ Received ] " + message, timeout)#if error, show: Message: $message between $self.source and $self.target, was not received after $timeout ms.