Skip to content

test_tool

Lor0l edited this page Mar 6, 2024 · 5 revisions

Test Tool for distributed tests and debugging

This section explains the test tool and describes how to use it. The SharkMessengerTestUI provides a tool for simple distributed load tests on the exchange of messages via a TCP connection between two peers (Alice and Bob in the following). The test procedure can be defined either manually by entering commands or automatically by a test script. At the end of a test run, log files with information about all sent and received messages can be created on both sides. These can be used to check whether all messages sent by Alice were correctly received by Bob. In case a bug occured the test scenario can be reproduced in a unit test for easier debugging. The test concept is shown by the following picture.


Test Script (optional)

The test script can be loaded as a .txt file when the program is started by passing the script path as a parameter. This parameter is optional, if it is not specified, the program is started without a test script. The script contains the commands to be executed and their parameters. One command per line, commands and all parameters are separated by spaces as in the following example.

[command] [parameter1] [parameter2] ...
[command] [parameter1] [parameter2] ...
...


Test Result Files

The test results can be saved in the form of two .csv files per peer in the same folder in which the executed program is located. When saving, an id of the corresponding test run can be given.

[testid]_tx_[peername].csv (OUT)

This file saves the sender, recipient, uri and the message id of all sent messages. The id's of the messages are unique for each (testrun, uri) and increment witch each further message. Example below.

sender,receiver,uri,id
alice,bob,test://t1,1
alice,bob,test://t1,2
alice,bob,test://t1,3
alice,bob,test://t1,4
alice,bob,test://t1,5


testid]_rx_[peername].csv (IN)

This file stores the sender, recipient, uri, message id, creation time and the received time of a received message. For each uri it also contains a line with the total number of messages received in this channel.This total number per channel is counted by the listener whereas the following lines with the information about each message come from actually saved messages in the the data storage. Example below.

sender,receiver,uri,id,creationTime,receivedTime
Listener : Total messages for test://t1: 5
alice,bob,test://t1,1,1709721342055,1709721342090
alice,bob,test://t1,2,1709721342061,1709721342161
alice,bob,test://t1,3,1709721342065,1709721342161
alice,bob,test://t1,4,1709721342070,1709721342170
alice,bob,test://t1,5,1709721342076,1709721342176


Relevant commands for testing

exec [in steps: boolean]

The execute method is used to execute a test script loaded at program start. The parameter ("true" or "false") decides whether the execution of each command from the script must be confirmed with enter.

openTCP [port]

By executing this command the peer offers a connection on the corresponding port number.

connectTCP [port] [host name]

By executing this command, you can connect to an open port of an offering peer.

closeTCP [port]

When this command is executed, no more new connections are accepted on the given port.

sendMessageTest [repetitions] [delay] [channel index] [sign] [encript] [message] [receivers]

This command wraps the sendMessage command, extends it with the repetitions and delay parameters and ensures that all outgoing messages are logged.
[repetitions] determines how often the message should be sent
[delay] determines how much time (in milliseconds) to wait before each transmission
[channel index] determines the channel by its index (command: lsChannel shows all channels; index starting with 0)
[sign] determines whether the message is signed
[encript] determines whether the message is encrypted
[message] message to be sent
[receivers] determines the receiver(s) (multiple receivers separated by a comma)

saveTestResuts [test id]

When this command is executed, the .csv files with the test results of this peer are created. The parameter testid determines the name of the files (see result).

resetTM

When this command is executed, the logs for the messages sent and received in the program (not the csv files) are deleted. deleted.
(to reset the status of this session, removeChannel needs to be implemented - better restart and delete the folder "sharkMessengerDataStorage" for reset)


How to test distribuited

Manually without script:

  1. Reset
    Make sure that all users, channels and messages from previous sessions have been deleted. to do this, simply delete the folder "sharkMessengerDataStorage" which is located in the same folder where the executed program is located.
  2. Start the program
    Execute "java -jar sharkMessengerUI.jar" on both peers and enter for example alice or bob when the username is requested.
  3. Establish connection
    Execute "openTCP 6666" on alice.
    Execute "connectTCP 6666 [IPAlice]" on bob.
  4. Create channel
    Execute "mkChannel test://t1 testChannel false" on both peers (the uri must be identical!).
  5. Execute test scenario
    Execute e.g. "sentMessageTest 10 100 0 false false hi_bob Bob" (to send 10 times "hi_bob" each with 100ms delay) on Alice or any other desired scenario.
    Repeat the sending as often as desired from one or both peers with parameters that fit your scenario.
  6. Save results
    Execute "saveTestRestults testRun1" on both peers.
    The .csv files are now saved under the names "testRun1_tx_Alice.csv", "testRun1_rx_Alice.csv", "testRun1_tx_Bob.csv" and "testRun1_rx_Bob.csv" are saved in the folder in which the executed program is located.
  7. Evaluate results
    By comparing the files txAlice - rxBob and txBob - rxAlice, you can now check which messages were successfully received and which were not.

Automatically with script:

  1. Reset
    (see manually)
  2. Start the program
    Execute "java -jar sharkMessengerUI.jar [script path]" on both peers and enter for example alice or bob when the username is requested.
    A script can also be loaded for only one peer.
  3. Establish a connection and create a channel.
    Either write the commands for setting up and creating a channel into the script.
    (In this case it should be noted that the commands are all executed immediately and in one go if the exec parater is "false")
    Or execute the connection and channel commands manually before executing the script.
  4. Execute test scenario
    Execute "exec true" on both peers.
    Or "exec false" on both peers and conform each command execution with enter.
  5. Save and evaluate results
    (see manually)

From distributed to unit tests

When finding a bug while running distributed tests the scenario can easily reproduced in a test environment to simplify the debugging process. The script code can be passed to the SharkMessengerUI instances as a string and than be executed at once or step by step. Check out the "ReproduceAndDebug" test class for examples.