This blog covers the Load testing automation of a REST service using a load test framework called Artillery, on Oracle Developer Cloud Service. The Nodejs based REST application will be deployed on Oracle Application Container Cloud Servic

 

     blog_pic.png

 

Note: For details on how to develop and deploy Nodejs based REST service application on Application Container Cloud using Developer Cloud service, please refer the blog link here.

 

Tech Stack Used

Eclipse: IDE for Artillery Load Test Script and Nodejs development.

Testing Framework: Artillery

Oracle Developer Cloud: For Load Test automation

Oracle Application Container Cloud: Cloud service to deploy Nodejs based REST web service, on which the load testing will be performed.

 

About Artillery

Artillery is a simple but powerful load testing toolkit. It can be used make your application perform better under high load. The test results of Artillery, gives us insight to make our application faster, more scalable, and more resilient.     For more information on Artillery, please visit - https://artillery.io/

 

Why Artillery?

 

About the Nodejs REST Application

The Nodejs REST application has a get and a post function. The get function gives a response with a static message and error attribute as false. While the post function ‘add’ gives the sum of the two numbers passed as input to the service. The Nodejs modules express and bodyPaser are being used to create the REST service. Below is the code snippet of main.js which contains the REST web service code.

 

var express = require("express");
var bodyParser = require("body-parser");
var app = express();
app.use(bodyParser.urlencoded());
app.use(bodyParser.json());
var router = express.Router();


router.get('/',function(req,res){
  res.json({"error" : false, "message" : "Hello Abhinav!"});
});


router.post('/add',function(req,res){
  res.json({"error" : false, "message" : "success", "data" : req.body.num1 + req.body.num2});
});


app.use('/',router);


app.listen(process.env.PORT || 3000,function(){
  console.log("I am listening at PORT 3000");
})

 

Please refer to my blog on Mocha.js test Automation, which explains the Node.js REST service development and deployment using Developer Cloud Service. It also  This service will be deployed on Oracle Application Container Cloud Service using the Node.js container.

 

Files for the Artillery Load Test

2017-07-03 22_42_47-JavaScript - ArtilleryTest_package.json - Eclipse.png

  1. add.yml – This is the configuration file for the load test using Artillery.
  2. number.csv – This file acts as a repository for the load test data. The add.yml file contains the
  3. package.json – It consists of the dependencies and command for the execution of Artillery load test

 

Description of the Files for the Artillery Load test:

add.yml

This is the configuration file for Artillery framework. In this file we configure the REST end point, that needs to be tested, test data payload file “numbers.csv” in this case and the test scenario for which the function type such as Post, Get etc are defined and the path URL for the method to be tested. We also define the test phases like duration and request arrival rate in this YAML file where duration means the test will last 60 seconds with 20 new virtual users (arriving every second (on average). You can give this file a name of your choice, but make sure to configure the same in the package.json in the test command.

config:
  target: 'https://mochatest-paasdemo015.apaas.us6.oraclecloud.com'
  phases:
    - duration: 60
      arrivalRate: 20
  payload:
    path: "numbers.csv"
    fields:
      - "num1"
      - "num2"
    order: "sequence"  
      
scenarios:
  - 
    name: "Test Add"
    flow:
      - 
       post:
        url: "/add"
        json:
             num1: ${{ num1 }}
             num2: ${{ num1 }}

 

 

package.json

The package.json contains the dependencies for the code execution. It also defines the command which is “artillery run add.yml”, to run the load test on the end point configured in the add.yml file which is being passed as an argument to the command for execution.

{
  "name": "LintingTest",
  "version": "0.0.1",
  "scripts": {
    "test": "artillery run add.yml"
  },
  "dependencies": {
  },
  "devDependencies": {
    "artillery": "^1.6.0"
  }
}

 

 

number.csv

This is a CSV file which contains the list of two number as test data for performing load testing on the add function of the REST endpoint.

1,2
2,3
3,4
4,5
5,6
6,7
7,8
8,9
9,10

 

Build Configuration:

Below are the screenshots for the build job configuration for the LoadTestBuild, which will perform load test on the Nodejs based REST API application deployed on Oracle Application Container Cloud, with the help of Artillery framework.

Give a name of your choice to the build job. For this blog I have named it as ‘LoadTestBuild’. As this is for Nodejs application, you can leave the JDK to default.

 

2017-07-03 16_25_30-Build_ BlogProject - Oracle Developer Cloud Service.png

Select the repository in which the load test related scripts and files have been uploaded.

Note: You may choose to use the same project which contains Nodejs application related code, for you load testing script(s).

 

2017-07-03 16_26_03-Build_ BlogProject - Oracle Developer Cloud Service.png

Here we set the SCM polling as the trigger. This ensures that, every time we upload code to the Git repository, it will trigger the ‘LoadTestBuild’, as shown in the build trigger diagram above in the blog.

 

2017-07-03 16_26_36-Build_ BlogProject - Oracle Developer Cloud Service.png

Configure the Nodejs version for the build to be 4.8.0, as shown in the screenshot below.

 

2017-07-03 16_27_08-Build_ BlogProject - Oracle Developer Cloud Service.png

We would be using the execute shell build step. As part of the build step, first we would change the folder to the project folder ‘ArtilleryTest’. We would be using the npm install to install all the Artillery module as in the screen shot below. Then use the ‘npm test’ command to execute the load test on the REST end point configured in the YAML file, described above in the blog.

 

2017-07-03 16_27_28-Build_ BlogProject - Oracle Developer Cloud Service.png

 

On execution, the load test results can be seen on the Build console, as show below.

2017-07-03 16_28_33-Build_ BlogProject - Oracle Developer Cloud Service.png

2017-07-03 16_29_30-Build_ BlogProject - Oracle Developer Cloud Service.png

2017-07-03 16_28_56-Build_ BlogProject - Oracle Developer Cloud Service.png

 

Decoding the above Results:

 

While the test is running, intermediate stats will be printed every 10 seconds (by default) and a complete report will be printed at the end of the test.

Scenarios launched - is the number of virtual users created in last 10 seconds.

Scenarios completed - is the number of virtual users that completed their scenarios in the preceding 10 seconds (or in the whole test). Note: this is the number of completed sessions, not the number of sessions started and completed in a 10 second interval.

Requests completed - is the number of HTTP requests and responses or WebSocket messages sent

RPS sent - is the average number of requests per second completed in the preceding 10 seconds (or throughout the test)

Request latency and Scenario duration - are in milliseconds, and p95 and p99 values are the 95th and 99th percentile values (a request latency p99 value of 400ms means that 99 out of 100 requests took 400ms or less to complete).If you see NaN (“not a number”) reported as a value, that means not enough responses have been received to calculate the percentile.

Codes - is the count of HTTP response codes.

 

Happy Coding!

**The views expressed in this post are my own and do not necessarily reflect the views of Oracle