Skip to content

Commit

Permalink
Merge pull request #127 from grafana/fix-examples
Browse files Browse the repository at this point in the history
Fix SharedArray examples
  • Loading branch information
federicotdn authored Dec 27, 2024
2 parents 0280bae + 78a3473 commit 72bdb73
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions k6/foundations/09.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const options = {
const pizzas = new Counter('quickpizza_number_of_pizzas');
const ingredients = new Trend('quickpizza_ingredients');

const customers = new SharedArray('all my customers', function () {
return JSON.parse(open('./data/customers.json')).customers;
const tokens = new SharedArray('all tokens', function () {
return JSON.parse(open('./data/tokens.json')).tokens;
});

export function setup() {
Expand All @@ -59,7 +59,7 @@ export function getPizza() {
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
headers: {
'Content-Type': 'application/json',
'Authorization': 'token abcdef0123456789',
'Authorization': 'Token ' + tokens[Math.floor(Math.random() * tokens.length)],
},
});
check(res, { "status is 200": (res) => res.status === 200 });
Expand Down
6 changes: 3 additions & 3 deletions k6/foundations/11.composability.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export const options = {
const pizzas = new Counter("quickpizza_number_of_pizzas");
const ingredients = new Trend("quickpizza_ingredients");

const customers = new SharedArray("all my customers", function () {
return JSON.parse(open("./data/customers.json")).customers;
const tokens = new SharedArray("all tokens", function () {
return JSON.parse(open("./data/tokens.json")).tokens;
});

export function setup() {
Expand All @@ -73,7 +73,7 @@ export function getPizza() {
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
headers: {
"Content-Type": "application/json",
'Authorization': 'token abcdef0123456789',
"Authorization": "Token " + tokens[Math.floor(Math.random() * tokens.length)],
},
});
check(res, { "status is 200": (res) => res.status === 200 });
Expand Down
6 changes: 3 additions & 3 deletions k6/foundations/12.modularization.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export const options = {
const pizzas = new Counter('quickpizza_number_of_pizzas');
const ingredients = new Trend('quickpizza_ingredients');

const customers = new SharedArray('all my customers', function () {
return JSON.parse(open('./data/customers.json')).customers;
const tokens = new SharedArray('all tokens', function () {
return JSON.parse(open('./data/tokens.json')).tokens;
});

export function setup() {
Expand All @@ -68,7 +68,7 @@ export function getPizza() {
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
headers: {
'Content-Type': 'application/json',
'Authorization': 'token abcdef0123456789',
'Authorization': 'Token ' + tokens[Math.floor(Math.random() * tokens.length)],
},
});
check(res, { "status is 200": (res) => res.status === 200 });
Expand Down
10 changes: 0 additions & 10 deletions k6/foundations/data/customers.json

This file was deleted.

10 changes: 10 additions & 0 deletions k6/foundations/data/tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tokens": [
"QivfLrMEt7thtJLQ",
"LJwhcDFp0TgvpOtg",
"WA1UafNBZrfQMpTf",
"NS9RTUgm42fgxe1E",
"O62N74Bbt3lNwY6l",
"pW6DNdnWppqMl1c6"
]
}

0 comments on commit 72bdb73

Please sign in to comment.