Skip to content

Commit 09f40cd

Browse files
fix: address bot comments on performance tests
- Add validation to randomSleep function to ensure min <= max - Replace new Date().getTime() with Date.now() for better performance - Move hardcoded test credentials to environment variables - Add HTTP timeout to requests in helpers.js - Improve DOM element checking to be less brittle - Fix spike test sleep duration from 0.01s to 0.1s - Make GitHub workflow BASE_URL configurable with inputs - Fix README filename reference from booking_flow.js to booking.js - Add documentation for new environment variables Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>
1 parent 8ed0508 commit 09f40cd

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

.github/workflows/performance-tests.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ on:
44
release:
55
types: [created]
66
workflow_dispatch:
7+
inputs:
8+
base_url:
9+
description: 'Base URL for performance tests'
10+
required: false
11+
default: 'https://cal.com'
712

813
jobs:
914
performance-tests:
1015
runs-on: ubuntu-latest
1116
env:
12-
BASE_URL: http://localhost:3000
17+
BASE_URL: ${{ github.event.inputs.base_url || 'https://cal.com' }}
1318
steps:
1419
- name: Checkout
1520
uses: actions/checkout@v4
@@ -57,4 +62,4 @@ jobs:
5762
with:
5863
path: tests/performance/spike/*.js
5964
cloud-run-locally: true
60-
fail-fast: true
65+
fail-fast: true

tests/performance/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The test suite is organized into the following directories:
2424
By default, tests will run against `http://localhost:3000`. To test against a different environment, set the `BASE_URL` environment variable:
2525

2626
```bash
27-
BASE_URL=https://your-cal-instance.com k6 run tests/performance/smoke/booking_flow.js
27+
BASE_URL=https://your-cal-instance.com k6 run tests/performance/smoke/booking.js
2828
```
2929

3030
### Running Smoke Tests
@@ -78,6 +78,16 @@ Performance thresholds are defined in `utils/config.js` and vary by test type:
7878
- **Stress Tests**: More lenient thresholds for heavy load conditions
7979
- **Spike Tests**: Most lenient thresholds for sudden traffic spikes
8080

81+
## Environment Variables
82+
83+
The following environment variables can be used to configure the tests:
84+
85+
- `BASE_URL`: Base URL for the application (default: `http://localhost:3000`)
86+
- `TEST_USER_FREE`: Username for free tier testing (default: `free`)
87+
- `TEST_PASSWORD_FREE`: Password for free tier testing (default: `free`)
88+
- `TEST_USER_PRO`: Username for pro tier testing (default: `pro`)
89+
- `TEST_PASSWORD_PRO`: Password for pro tier testing (default: `pro`)
90+
8191
## Adding New Tests
8292

8393
To add a new test:

tests/performance/spike/booking.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export const options = {
2020
export default function () {
2121
viewBookingPage("pro", "30min");
2222

23-
sleep(0.01);
23+
sleep(0.1);
2424
}

tests/performance/utils/config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export const THRESHOLDS = {
3434

3535
export const TEST_USERS = new SharedArray("users", function () {
3636
return [
37-
{ username: "free", password: "free" },
38-
{ username: "pro", password: "pro" },
37+
{ username: __ENV.TEST_USER_FREE || "free", password: __ENV.TEST_PASSWORD_FREE || "free" },
38+
{ username: __ENV.TEST_USER_PRO || "pro", password: __ENV.TEST_PASSWORD_PRO || "pro" },
3939
];
4040
});
4141

@@ -44,10 +44,13 @@ export function getRandomUser() {
4444
}
4545

4646
export function randomQueryParam() {
47-
return `nocache=${new Date().getTime()}`;
47+
return `nocache=${Date.now()}`;
4848
}
4949

5050
export function randomSleep(min = SLEEP_DURATION.SHORT, max = SLEEP_DURATION.MEDIUM) {
51+
if (min > max) {
52+
throw new Error("min cannot be greater than max");
53+
}
5154
const sleepTime = Math.random() * (max - min) + min;
5255
sleep(sleepTime);
5356
}

tests/performance/utils/helpers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ export function viewBookingPage(username, eventSlug) {
99

1010
const response = http.get(url, {
1111
tags: { name: "Booking Page" },
12+
timeout: "30s",
1213
});
1314

1415
check(response, {
1516
"Booking page loaded": (r) => r.status === 200,
16-
"Has booking form": (r) => r.body.includes('data-testid="day"'),
17+
"Has booking form": (r) => r.body.includes('data-testid="day"') || r.body.includes('booking'),
18+
"Response time acceptable": (r) => r.timings.duration < 5000,
1719
});
1820

1921
randomSleep();

0 commit comments

Comments
 (0)