Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock data update while running the config.yml file #2605

Open
PoojaArora29 opened this issue Mar 27, 2024 · 0 comments
Open

Mock data update while running the config.yml file #2605

PoojaArora29 opened this issue Mar 27, 2024 · 0 comments

Comments

@PoojaArora29
Copy link

PoojaArora29 commented Mar 27, 2024

Hi all,

i am using artillery for a miniapp which has graphql queries. So far it works fine when i have loaded the mocks when i do yarn start but i have couple of scenario for which i want to use different mocks that changes the response of the scenario.
Currently i have .js file to overwrite the mock file which worked fine in local but it does not work when using docker images.

Version info:
Artillery : 2.0.0-35
Node.js : v16.18.1

Running this command:
Local : yarn performance-test-bff
Jenkins/docker : ./batect performance-test-bff

I expected to see this happen:

Local: overwrite files to use new mock (cannot think any simpler way than this otherwise yarn start is required to take mock effect)

Instead, this happened:

Works fine in local need it the same solution for docker.

Files being used:

Config.yml

config:
    processor: ./helper.js
    environments:
        local:
            target: http://localhost:5000/
            phases:
                - duration: 10
                  arrivalRate: 1
                  rampTo: 10
                  name: Ramp up load
                - duration: 30
                  arrivalRate: 1
                  name: Sustained load
        dev:
            target: url
            phases:
                - duration: 10
                  arrivalRate: 1
                  rampTo: 10
                  name: Ramp up load
                - duration: "{{ $processEnvironment.duration }}"
                  arrivalRate: "{{ $processEnvironment.arrivalRate }}"
                  name: Sustained load
        ppte:
            target: url
            phases:
                - duration: 10
                  arrivalRate: 1
                  rampTo: 10
                  name: Ramp up load
                - duration: "{{ $processEnvironment.duration }}"
                  arrivalRate: "{{ $processEnvironment.arrivalRate }}"
                  name: Sustained load
    # Load & configure a couple of useful plugins
    # https://docs.art/reference/extensions
    plugins:
        expect: { }
        metrics-by-endpoint:
            useOnlyRequestNames: true
    variables:
        ServiceName:
            - uri
        content-type:
            - "application/json"
        accessToken:
            - “userTokenForAuth”


scenarios:

    - name: "My test"
       beforeRequest: beforeEdgeRequest
      flow:
          - post:
                name: "my test"
                url: "{{ ServiceName }}"
                headers:
                    accessToken: "{{ accessToken }}"
                    x-correlationId: "{{ $randomString() }}"
                json:
                    query: |
                        query myQueryHere
                    variables:
                        inputValue: "randomId"
                capture:
                    - json: "$.data"
                      as: data
                expect:
                    - statusCode: 200
                    - contentType: json

Helper.js

use strict";
const fs = require('fs')
 
fs.writeFileSync("./../pathFile/newMock.json", ./../pathFile/existingMock.json
         
module.exports = {
#overwriting the mock which is loaded initially in yarn start to take immediate effect of mock
    beforeEdgeRequest(requestParams, context, ee, next) {
         console.log('Stub Response set ');             fs.writeFileSync("./../pathToFile/existingMock", ./../pathFile/newMock.json);
                        
         return next();
    }
}
 

Commands in sequence from batect to app/server/package.json

Batect.yml

performance-test-bff:
  description: Run bff performance tests
  run:
      container: build-env
      command: yarn performance-test-bff
      environment:
          ARTILLERY_ENVIRONMENT: dev
          ARTILLERY_ARRIVAL_RATE: 1
          ARTILLERY_DURATION: 60
          HTTP_PROXY: ''
  dependencies:
      - express
      - mocks
 

Root/package.json

“ performance-test-bff": "yarn workspace server performance-test"

App/server/package.json

“ performance-report": "artillery report --output ./performance/results/bff-performance-test-report.html performance/results/bff-performance-test-report.json",
"performance-run": "arrivalRate=$ARTILLERY_ARRIVAL_RATE duration=$ARTILLERY_DURATION artillery run -e $ARTILLERY_ENVIRONMENT --output ./performance/results/bff-performance-test-report.json ./performance/config.yml",
"performance-test": "yarn preperformance-test && yarn performance-run && yarn performance-report",
"preperformance-test": "rimraf ./performance/results && mkdirp ./performance/results "

i have added one scenario here but actually there are multiple flows in my actual project. I am using same scenario in the same file and using helper.json to update mocks while running perf. This approach works in local but when i run it in jenkins it used docker.

please ignore indentation and spellings . It is just copy pasted and manually entered from mobile 😭😭

Thanks a lot for your help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant