LogoLogo
HomeSign UpGithub
  • Home
  • Release Notes
  • Getting Started
    • Create your first Test
    • Create Run Settings
    • Analyze the results
      • Job Summary
      • Logs
      • State
      • Payload
    • Look deeper with Metrics
  • Concepts
    • Workspaces
      • Role Based Access Control (RBAC)
      • Invitation Management
      • GitHub Integration
      • Deletion of Workspaces
      • System Status
    • Understanding Tests
      • Stages Management
        • Init Stage
        • Running Stage(s)
        • Finished State
      • Generating Messages
        • Scripting Environment
        • State Object
      • Response Handler
      • Preview Tests
      • Exporting/Importing Tests
        • Import OpenAPI JSON/YAML
      • Locking/Unlocking a test
    • Stateful Simulation
      • Mapping the IoT device lifecycle
    • Protocol Settings
      • MQTT
      • HTTP
      • Using other protocols
    • Run Settings
      • Network Simulation
      • Execution Strategies
      • Client Distribution
    • Scenarios
    • Glob Storage
    • Metrics
    • Mailbox
    • Licensing and Limits
    • Deployment Models
  • Additional Helpers
    • External Libraries
    • Inbuilt Libraries
    • IoTIFY Helper Functions
      • Job Functions
      • Messaging Functions
      • Glob Functions
      • Metrics Functions
      • Mailbox Functions
      • Data Generation Functions
  • platform integrations
    • AWS IoT Connector
  • Guides
    • Smart City
    • Smart Home
    • Load Testing Kafka
  • IoT Testing
    • Overview
      • Feed offline sensor data from Google Sheets to your IoT platform
    • Functional Testing
      • Basic functional test
      • Geofencing Validation
    • Performance Testing
      • MQTT end to end latency Measurement
    • Security Testing
    • Load Testing
    • Test Automation & CI/CD integration
  • API
    • Simulation API
    • Glob APIs
    • Metrics API
  • Glossary
  • Create Account
  • TEMP
    • Getting Started
      • Beginner
      • Developer
      • Tester
    • Walkthrough
    • Protocol Settings
      • CoAP
      • Raw (TCP/UDP/TLS/DTLS)
      • LWM2M
      • NONE
    • Under the hood
    • Google Sheets API
    • Azure IoT
    • Losant IoT
      • Losant Connector
      • Parking Space Management
      • Waste Management
      • Connected Truck
      • Delivery Van
    • Google Cloud IoT Core
    • IBM Cloud
      • Simple Messaging
      • IBM Bluemix: Monitoring Energy Consumption
    • Dweet.io
    • JMeter and why it fails at IoT
Powered by GitBook
On this page

Was this helpful?

  1. Additional Helpers
  2. IoTIFY Helper Functions

Job Functions

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()

Use the 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.

Function:
getRunSettings()            //no arguments are required

console.log("The current run setting is "+getRunSettings().name)

//returns an object with the full run settings
Response:
{
	id: '6246fbe5fdee1fd07c3bb331',
	name: 'Default',
	interval: 10000,
	iteration: 10,
	clients: 10,
	totalClients: 10,
	clientIdOffset: 0,
	clientGroupSize: 1000,
	maxParallelClients: 0,
	maxMessagesPerSecond: 0,
	captureLogs: true,
	captureState: true,
	capturePayload: false,
	interClientGap: 0,
	interGroupGap: 0,
	externalSync: true,
	strategy: 'Default',
	groupIndex: 0
}

The current run setting is Default

jobClients()

This function returns the total number of clients that are being simulated in the current job.

Function:
jobClients()            //no arguments are required

console.log("Total clients for the job are "+jobClients())
//returns a number with the number of clients
Response:
10

Total clients for the job are 10

jobId()

Returns the assigned name of the simulation job. This could be used to store the results in a database.

Function:
jobId()                    //no arguments are required

console.log("The current running job is "+jobId())

//returns a string with the job name generated by the system
Response:
ebaf0e09-7d8a-4b53-8182-55a2d3dc2230

The current running job is ebaf0e09-7d8a-4b53-8182-55a2d3dc2230

jobInterval()

Returns the time interval in seconds between each iteration.

Function:
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
Response:
10000

There is a gap of 10000 seconds between iterations

jobRepeat()

Returns the total number of iterations specified in the job.

Function:
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
Response:
10

The job will repeat 10 times

index() or iteration()

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

Function:
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
Response:
3
3

The job is currently in iteration number 3

client()

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.

Function:
client()                    //no arguments are required

console.log("The current client ID is "+client())

//returns a number with the current client ID
Response:
15

The current client ID is 15

assert()

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 assert() function.

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 retval does not equal to 123.

//Takes a boolean condition and a string message as arguments
assert(condition, message)

assert(retval == 123, "Return value doesn't equal "+123);
PreviousIoTIFY Helper FunctionsNextMessaging Functions

Last updated 2 years ago

Was this helpful?