Giter Club home page Giter Club logo

performance-orb's Introduction

Topcoder - JMeter Performance Testing Framework - Part 2

Requirements

Project structure

  • jmeter
    • JsonSample.groovy
      • Custom Json sampler in groovy
  • pom.xml
    • Maven configuration file
  • .circleci
    • orb.yml

What is provided in this project?

Sensitive variables

Sensitive informations are now loaded though environments variables.

  • User credentials
  • M2M credentials
  • TopCoder API URL
    • This one is not sensitive but loading it through env var instead of csv or json is more convenient.

Adding new one is as simple as adding new user variable within JMeter. The value of the variable has just to be set to :

${__groovy(System.getenv("ENV_VAR_NAME"))}

You can see exemples in this example JMeter test file

  • Authentication/Crendentials
  • Resource API[DEV]/API Variables

As these env vars are copied to standard JMeter vars, they can be used anywhere in the test plan with ${var}.

Json datasets

A groovy script JsonSample.groovy is provided to load data from Json files. It has been implemented using these datasets under Create Resource Roleof the test plan.

The script is fully generic and can be used for any json file that has an array as the root object (see bellow).

Format requirements

The JSon root object must be an array, the content of it is not restricted.

[
  {
    "memberHandle": "handle1",
    "httpCode": 200
  },
  {
    "memberHandle": "handle2",
    "httpCode": 200
  }
]

Usage

The has to be used as a JSR223 Sampler or JSR223 PreProcessor with groovy interpreter.

Here are the required parameters

  • File Name: JsonSample.groovy (script path relative to test directory)

  • Parameters: json dataset location + destination var, separated by space.

    • ie: /data/sample.json myvar

Examples

You can see an exemple of using the parser as a Sample in the create-resource-role-by-admin section of the test plan

An exemple using it as a pre-processor is available with create-resource-role-by-m2m, an inline groovy script is then used to remove unneeded fileds from data, but it can also be written as a plain groovy script. See the body of the Create active, read and write access resource role by M2Mrequest.

${__groovy(
	import groovy.json.JsonOutput
	JsonOutput.toJson(vars.getObject("resource_role_m2m").findAll {k\,v -> !['httpCode'\, 'message'].contains(k)} )
)}

Behavior

Each of the JMeter gets a different value, very similar to the CSV Dataset Behavior.

If there is no more data to load, the reading restarts at the beginning.

Each element of the Json array is stored as Object to the JMeter variable whose is name from the second groovy script parameter (see Parameters above).

The result is also stored as the SampleResult if used as a Sample and can be use by the orginal Jmeter parsers (ie. JsonPath extractor)

Finally the element json string is stored inside the varname_json var.

The result can alos be processed by any of the JMeter scripting languages, an exemple is provided in the JMeter test plan.

// Extracting simple json object (no children) to vars named with the keys of the json data
def data = vars.getObject("tokens")
data.entrySet().each {
	vars.put(it.getKey(), it.getValue())
}

Testing

๐Ÿ’ก Integration with CircleCI

Publishing this ORB :

Use CircleCI CLI :

[Optional] โ„น๏ธ Register a namespace if not already done : https://circleci.com/docs/2.0/orb-author-intro/#register-a-namespace

  1. Create (If not already created) the orb under your namespace and orb name . I have used topcoder-platform/performance-orb where topcoder-platform is namespace and performance-orb is the orb name.

    circleci orb create topcoder-platform/performance-orb
    
  2. Then publish it. (every time you update, publish with newer version)

    circleci orb publish .circleci/orb.yml topcoder-platform/performance- [email protected]
    

โœ… If any other namespace/orb name/ version is used change that accordingly while importing the orb.

This can be referred as a sample.

Importing this ORB :

To import and use this orb , import it in your circleci configuration like below under the root node. :

format should be :

orbs:
  orb-name: namespace/orb-name@version

For example :

orbs:
  performance-orb: topcoder-platform/[email protected]

๐Ÿ’ก According to this documentation :

Pipeline parameters can only be resolved in the .circleci/config.yml file

So, the pipeline parameter run_performancetesting needs to be declared in individual config file and inside parameter field, like below :

parameters:
  run_performancetesting:
    default: false
    type: boolean  

Sample HTML [report](Challenge API Performance Test Report in HTML.PNG) :

Reference

Additional Environment Variables :

Along with API's own circleci environment variables, the following environment varibales should be set in circleci.

Variable Explanation Example
SERVER_URL Required. The base url of the Application which needs to be tested. https://api.topcoder-dev.com
JOB_CLEAN_API Required. The cleanup API for that application. For example resources/internal/jobs/clean
JMX_LOCATION Required. Location of the .jmx file ./test
JMX_FILE Required. Name of the jmx file to be used. Resource API.jmx

Use a classic Maven/Java pipeline : Language Guide: Java (with Maven)

Provided required environment variables : Using Environment Variables

Resources

CircleCI Orb Docs - Docs for using and creating CircleCI Orbs.

Errors

All errors reported by JMeter where already present in the provided tests plan, it was not asked to solve them.

  • User 2&3 Invalid credentials
  • RessourceRole creation
    • Provided ids already exists, not modified to avoid creating millions of entries in the ressource-role database.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.