The Job functions allow you to get information on the currently running job so that you can create tests that can work dynamically in relation to the current state of the simulation.
The various functions are listed below:
getRunSettings()function to retrieve the run settings for the currently running job. The function returns an object with all the data pertaining to the run settings.
getRunSettings() //no arguments are required
console.log("The current run setting is "+getRunSettings().name)
//returns an object with the full run settings
The current run setting is Default
This function returns the total number of clients that are being simulated in the current job.
jobClients() //no arguments are required
console.log("Total clients for the job are "+jobClients())
//returns a number with the number of clients
Total clients for the job are 10
Returns the assigned name of the simulation job. This could be used to store the results in a database.
jobId() //no arguments are required
console.log("The current running job is "+jobId())
//returns a string with the job name generated by the system
The current running job is ebaf0e09-7d8a-4b53-8182-55a2d3dc2230
Returns the time interval in seconds between each iteration.
jobInterval() //no arguments are required
console.log("There is a gap of "+jobInterval()+" seconds between iterations")
//returns a number with the time interval in seconds
There is a gap of 10000 seconds between iterations
Returns the total number of iterations specified in the job.
jobRepeat() //no arguments are required
console.log("The job will repeat "+jobRepeat()+" times")
//returns a number with the amount of times the simulation will repeat
The job will repeat 10 times
For the simulations, you will specify the number of iterations that a test should run for. To get the value of the current iteration that the simulation is in, you can use the index() or iteration() functions
index() //no arguments are required
iteration() //no arguments are required
console.log("The job is currently in iteration number "+iteration())
//returns a number with the current iteration
The job is currently in iteration number 3
For the simulations, you may need to implement client-specific behaviours. The current client ID can be determined within the test by using the client() function.
client() //no arguments are required
console.log("The current client ID is "+client())
//returns a number with the current client ID
The current client ID is 15
Usually, an iteration for a client will be marked as failed, when the client is unable to publish a message to the server within the given timeout period. However, there may be cases where you would like to declare a test as failed when certain criteria are not met.
When using IoTIFY for testing, you could force a test iteration to be failed even if message sending is successful using test assertion with the
The function takes two parameters:
condition: A boolean condition that should be tested for truth (true) message: A string describing the cause of assertion failure which can be stored in test results.
For example, the following statement checks for an assertion failure in your template and marks the test result as failed, if
retvaldoes not equal to 123.
//Takes a boolean condition and a string message as arguments
assert(retval == 123, "Return value doesn't equal "+123);