diff --git a/performance/get-all-movies-then-get-one.yml b/performance/get-all-movies-then-get-one.yml index d3af13b..08ef609 100644 --- a/performance/get-all-movies-then-get-one.yml +++ b/performance/get-all-movies-then-get-one.yml @@ -48,15 +48,14 @@ config: - duration: 10min arrivalRate: 100 name: Baseline - scenarios: - name: get-all-movies-then-get-one - beforeScenario: myBeforeScenarioHandler flow: - get: name: GET /movies url: /movies + afterResponse: getRandomMovieId - get: name: GET /movies/{id} url: /movies/{{ movieId }} \ No newline at end of file diff --git a/performance/processor.js b/performance/processor.js index 42331fd..305858d 100644 --- a/performance/processor.js +++ b/performance/processor.js @@ -1,13 +1,16 @@ -const moviesData = require('../tmdb_movies.json'); +let movies; -function myBeforeScenarioHandler(context, ee, next) { - const randomMovie = moviesData[Math.floor(Math.random() * moviesData.length)]; - - context.vars.movieId = randomMovie.id; +function getRandomMovieId(req, res, context, ee, next) { + if (!movies) { + movies = JSON.parse(res.body); + } + const randomMovie = movies[Math.floor(Math.random() * movies.length)]; + context.vars.getRandomMovieId = randomMovie.id; next(); }; module.exports = { - myBeforeScenarioHandler -} \ No newline at end of file + getRandomMovieId +} +