-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactor new
command
#4153
base: master
Are you sure you want to change the base?
Refactor new
command
#4153
Changes from 6 commits
d254f00
e7e95f1
c3f84ba
fea3e7f
b1af40f
b3e99b8
6423d09
1d8d321
5cf5916
beda4b1
9b0ab6d
833e52f
c0fc8d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { browser } from "k6/browser"; | ||
import http from "k6/http"; | ||
import { sleep, check } from 'k6'; | ||
|
||
const BASE_URL = __ENV.BASE_URL || "https://quickpizza.grafana.com"; | ||
|
||
export const options = { | ||
scenarios: { | ||
ui: { | ||
executor: "shared-iterations", | ||
options: { | ||
browser: { | ||
type: "chromium", | ||
}, | ||
}, | ||
}, | ||
}, {{ if .EnableCloud }} | ||
cloud: { {{ if .ProjectID }} | ||
projectID: {{ .ProjectID }}, {{ else }} | ||
// projectID: 12345, // Replace this with your own projectID {{ end }} | ||
name: "{{ .ScriptName }}", | ||
}, {{ end }} | ||
}; | ||
|
||
export function setup() { | ||
let res = http.get(BASE_URL); | ||
if (res.status !== 200) { | ||
throw new Error( | ||
`Got unexpected status code ${res.status} when trying to setup. Exiting.` | ||
); | ||
} | ||
} | ||
|
||
export default async function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really a nitpick, and a personal preference, but I would find the code more readable with actual newlines 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copy pasted it from the QuickPizza repo 🙈 Better now? |
||
let checkData; | ||
const page = await browser.newPage(); | ||
try { | ||
await page.goto(BASE_URL); | ||
checkData = await page.locator("h1").textContent(); | ||
check(page, { | ||
header: checkData === "Looking to break out of your pizza routine?", | ||
}); | ||
await page.locator('//button[. = "Pizza, Please!"]').click(); | ||
await page.waitForTimeout(500); | ||
await page.screenshot({ path: "screenshot.png" }); | ||
checkData = await page.locator("div#recommendations").textContent(); | ||
check(page, { | ||
recommendation: checkData !== "", | ||
}); | ||
} finally { | ||
await page.close(); | ||
} | ||
sleep(1); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import http from 'k6/http'; | ||
import { sleep, check } from 'k6'; | ||
|
||
export const options = { | ||
vus: 10, | ||
duration: '30s',{{ if .EnableCloud }} | ||
cloud: { {{ if .ProjectID }} | ||
projectID: {{ .ProjectID }}, {{ else }} | ||
// projectID: 12345, // Replace this with your own projectID {{ end }} | ||
name: "{{ .ScriptName }}", | ||
}, {{ end }} | ||
}; | ||
|
||
export default function() { | ||
let res = http.get('https://quickpizza.grafana.com'); | ||
check(res, { "status is 200": (res) => res.status === 200 }); | ||
sleep(1); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import http from "k6/http"; | ||
import { check, sleep } from "k6"; | ||
|
||
const BASE_URL = __ENV.BASE_URL || 'https://quickpizza.grafana.com'; | ||
|
||
export const options = { | ||
vus: 10, | ||
stages: [ | ||
{ duration: "10s", target: 5 }, | ||
{ duration: "20s", target: 10 }, | ||
{ duration: "1s", target: 0 }, | ||
], thresholds: { | ||
http_req_failed: ["rate<0.01"], | ||
http_req_duration: ["p(95)<500", "p(99)<1000"], | ||
},{{ if .EnableCloud }} | ||
cloud: { {{ if .ProjectID }} | ||
projectID: {{ .ProjectID }}, {{ else }} | ||
// projectID: 12345, // Replace this with your own projectID {{ end }} | ||
name: "{{ .ScriptName }}", | ||
}, {{ end }} | ||
}; | ||
|
||
export function setup() { | ||
let res = http.get(BASE_URL); | ||
if (res.status !== 200) { | ||
throw new Error( | ||
`Got unexpected status code ${res.status} when trying to setup. Exiting.` | ||
); | ||
} | ||
} | ||
|
||
export default function() { | ||
let restrictions = { | ||
maxCaloriesPerSlice: 500, | ||
mustBeVegetarian: false, | ||
excludedIngredients: ["pepperoni"], | ||
excludedTools: ["knife"], | ||
maxNumberOfToppings: 6, | ||
minNumberOfToppings: 2 | ||
}; | ||
|
||
let res = http.post(BASE_URL + "/api/pizza", JSON.stringify(restrictions), { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-User-ID': 23423, | ||
dgzlopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}); | ||
|
||
check(res, { "status is 200": (res) => res.status === 200 }); | ||
console.log(res.json().pizza.name + " (" + res.json().pizza.ingredients.length + " ingredients)"); | ||
sleep(1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed that both
k6 new
andk6 new --template minimal
work, and it looks like it generates the same script file. As a result I would keep documenting an example of the default behavior ofk6 new
here 🙇🏻Also as we're at it, it wasn't immediatly obvious to me that the
k6 new
command supports a file argument (not flag) from the examples, we might want to also add one demonstrating that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! I changed the help text a bit. Wdyt?