Artillery: How to write my own engine? Docs?

Created on 27 Jul 2018  路  2Comments  路  Source: artilleryio/artillery

Hi i found the repository "https://github.com/shoreditch-ops/artillery-engine-kinesis" which seems to solve exactly what i need - writing my own engine.. I did it already by forking the whole artillery repository and got it running, but it feels as a total overkill to fork the whole thing just to introduce a new engine.

But when i see code like this:

      let runnerEngines = _.map(
      Object.assign({}, Engines, runnableScript.config.engines),
      function loadEngine(engineConfig, engineName) {
        let moduleName = 'artillery-engine-' + engineName;
        try {
          if (Engines[engineName]) {
            moduleName = './engine_' + engineName;
          }
          let Engine = require(moduleName);
     ....

-> the runner code is hardcoded looking into his own folder relatively with all the entries of "Engines"... i don't see how this should be dynamically able to pick up some new written engines at all oO

So... how should this work?

Most helpful comment

Another way to do this is to create a package that has a dependency on both artillery and your custom engine (could be installed from ./artillery-engine-custom), this way artillery core will be able to require in your custom engine correctly.

In your root project folder:

my-script.yml

An artillery script using your custom engine.

package.json

{
  "name": "my-load-tests",
  "version": "0.1.0",
  "scripts": {
    "test": "artillery run ./my-script.yml"
  },
  "dependencies": {
    "artillery": "^1.6.0-27",
    "artillery-engine-realm": "file:artillery-engine-custom"
  }
}

A directory called artillery-engine-custom

This should be a module named "artillery-engine-custom" which main script should export an engine.

All 2 comments

hi @rvetere, the way to get it going locally is:

  1. Clone Artillery, run npm install in the directory, this will let you run a local copy of Artillery with ./bin/artillery
  2. In the directory where your custom engine code is (let's say artillery-engine-rvetere) run npm link
  3. Back inside Artillery's source dir run npm link artillery-engine-rvetere (more info on npm link)

This will allow that copy of Artillery to find and load your custom engine. It's important that you set the engine field of your scenario:

config:
  target: "some.target"
scenarios:
  - name: "Custom engine scenario"
    engine: "rvetere"
    flow:
     - do: something
     - do: something else

Another way to do this is to create a package that has a dependency on both artillery and your custom engine (could be installed from ./artillery-engine-custom), this way artillery core will be able to require in your custom engine correctly.

In your root project folder:

my-script.yml

An artillery script using your custom engine.

package.json

{
  "name": "my-load-tests",
  "version": "0.1.0",
  "scripts": {
    "test": "artillery run ./my-script.yml"
  },
  "dependencies": {
    "artillery": "^1.6.0-27",
    "artillery-engine-realm": "file:artillery-engine-custom"
  }
}

A directory called artillery-engine-custom

This should be a module named "artillery-engine-custom" which main script should export an engine.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericmacfarland picture ericmacfarland  路  6Comments

hartmut-co-uk picture hartmut-co-uk  路  4Comments

sonisaurabh19 picture sonisaurabh19  路  5Comments

DanielMSchmidt picture DanielMSchmidt  路  4Comments

endrureza picture endrureza  路  5Comments