Skip to content

Fixed faulty k6 tests, due to jwt problems, and added smoke and spike tests#38

Merged
alxmra merged 1 commit intodevfrom
OLS-68-Non-functional-tests-k6
Dec 16, 2025
Merged

Fixed faulty k6 tests, due to jwt problems, and added smoke and spike tests#38
alxmra merged 1 commit intodevfrom
OLS-68-Non-functional-tests-k6

Conversation

@Alexandre-A
Copy link
Copy Markdown
Contributor

Fixed faulty k6 tests, due to jwt problems, and added smoke and spike tests

  • Improvements to run-k6-tests.sh:

    • Added command-line arguments for test type (smoke, load, or spike) and base URL, with validation and helpful usage messages.
    • Improved environment checks: verifies K6 installation and attempts to install it automatically on Linux/macOS, with clear error messages for unsupported systems.
    • Checks application health before running tests and provides actionable instructions if the application is not healthy.
    • Enhanced output formatting with color-coded messages, timestamps, and clear result locations for easier user experience.
    • Consolidated and organized test results in a timestamped results directory, including JSON reports and logs.
  • Addition of Sample Test Summary Output:

    • Added a new summary.json file in the k6/results directory, providing a sample of summarized spike test results for reference or automated post-processing.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@alxmra alxmra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty good 👍 👍

@alxmra alxmra merged commit 02620be into dev Dec 16, 2025
11 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes JWT authentication issues in K6 performance tests and adds comprehensive test infrastructure with support for smoke, load, and spike test scenarios.

  • Enhanced test runner script with command-line arguments, automatic K6 installation, health checks, and improved output formatting
  • Completely rewrote K6 test suite to include proper authentication flow, multiple test scenarios, and comprehensive API endpoint coverage
  • Added sample test summary output for reference

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.

File Description
k6/run-k6-tests.sh Enhanced test runner with CLI arguments, OS-specific K6 installation, health checks, colored output, and timestamped results management
k6/load-test.js Complete rewrite adding authentication, setup/teardown functions, multiple test scenarios (smoke/load/spike), grouped endpoint testing, and custom summary generation
k6/results/summary.json Sample spike test results showing metrics structure for automated post-processing (new file)
Comments suppressed due to low confidence (3)

k6/load-test.js:71

  • Unused variable authToken.
let authToken = null;

k6/load-test.js:72

  • Unused variable testUserId.
let testUserId = null;

k6/load-test.js:45

            http_req_duration: ['p(95)<500'],    // 95% requests < 500ms

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread k6/load-test.js

sleep(1);

// Group 4: Pricing endpoints (requires auth)
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "Group 4: Pricing endpoints" but based on the pattern in the code, this is actually the fifth group. This inconsistency in group numbering could be confusing. Consider renumbering all group comments sequentially to match their actual order in the code.

Suggested change
// Group 4: Pricing endpoints (requires auth)
// Group 5: Pricing endpoints (requires auth)

Copilot uses AI. Check for mistakes.
Comment thread k6/results/summary.json
"http_req_duration_p95": 101.17221939999999,
"http_req_duration_p99": 0,
"http_req_failed": 0.2221761658031088,
"error_rate": 0,
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The http_req_failed metric shows approximately 22.2% failure rate (0.2221761658031088), but the error_rate is 0. This is logically inconsistent - if 22% of HTTP requests failed, the error rate should reflect this. Either the http_req_failed value should account for expected 404/400 responses and not count them as failures, or the error_rate should be non-zero to match the failed requests.

Suggested change
"error_rate": 0,
"error_rate": 0.2221761658031088,

Copilot uses AI. Check for mistakes.
Comment thread k6/run-k6-tests.sh
Comment on lines +152 to 154
exit $EXIT_CODE
echo "4. Database Connections - Should show increased activity"
echo "5. Logs in Loki - Should show increased log volume" No newline at end of file
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are unreachable code. The script exits at line 152 with the EXIT_CODE value, so lines 153-154 will never be executed. These lines should be removed or moved to before the exit statement if they're intended to be part of the output.

Copilot uses AI. Check for mistakes.
Comment thread k6/load-test.js
Comment on lines +45 to +46
http_req_duration: ['p(95)<500'], // 95% requests < 500ms
http_req_duration: ['p(99)<1500'], // 99% requests < 1.5s
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate threshold key 'http_req_duration'. The second declaration on line 46 will override the first one on line 45. Either combine these into a single threshold with multiple conditions, or use different threshold names if they serve different purposes.

Suggested change
http_req_duration: ['p(95)<500'], // 95% requests < 500ms
http_req_duration: ['p(99)<1500'], // 99% requests < 1.5s
http_req_duration: ['p(95)<500', 'p(99)<1500'], // 95% requests < 500ms, 99% requests < 1.5s

Copilot uses AI. Check for mistakes.
Comment thread k6/results/summary.json
"http_reqs": 9650,
"http_req_duration_avg": 16.3323620996892,
"http_req_duration_p95": 101.17221939999999,
"http_req_duration_p99": 0,
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The p99 metric is set to 0, which is inconsistent with the other metrics and highly unlikely in a real performance test. The p99 response time should be greater than or equal to the p95 value (101.17ms). This appears to be incorrect sample data and should be corrected to a realistic value, such as a number greater than the p95 value.

Suggested change
"http_req_duration_p99": 0,
"http_req_duration_p99": 120.0,

Copilot uses AI. Check for mistakes.
Comment thread k6/results/summary.json
"http_req_duration_avg": 16.3323620996892,
"http_req_duration_p95": 101.17221939999999,
"http_req_duration_p99": 0,
"http_req_failed": 0.2221761658031088,
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values show 9650 total http_reqs but 9648 successful_requests, which means 2 requests failed. However, the http_req_failed rate of 0.222 (22.2%) would indicate approximately 2,142 failed requests (9650 * 0.222), not 2. This mathematical inconsistency in the sample data should be corrected to ensure the metrics align properly.

Suggested change
"http_req_failed": 0.2221761658031088,
"http_req_failed": 0.000207254,

Copilot uses AI. Check for mistakes.
Comment thread k6/load-test.js
Comment on lines +71 to +72
let authToken = null;
let testUserId = null;
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variables 'authToken' and 'testUserId' are declared but never used in the code. These should be removed to improve code clarity, or utilized if they were intended for a specific purpose.

Suggested change
let authToken = null;
let testUserId = null;

Copilot uses AI. Check for mistakes.
Comment thread k6/load-test.js

sleep(1);

// Group 2: Authentication endpoints
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "Group 2: Authentication endpoints" but this is the third group in the code (after "Public Endpoints" and "Search and Filter Endpoints"). Consider updating the comment to "Group 3" to maintain consistency with the group numbering, or renumber all groups for clarity.

Suggested change
// Group 2: Authentication endpoints
// Group 3: Authentication endpoints

Copilot uses AI. Check for mistakes.
Comment thread k6/load-test.js

sleep(1);

// Group 3: Authenticated endpoints
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "Group 3: Authenticated endpoints" but this is the fourth group in the code. This inconsistency in group numbering could be confusing. Consider renumbering all group comments sequentially to match their actual order in the code.

Suggested change
// Group 3: Authenticated endpoints
// Group 4: Authenticated endpoints

Copilot uses AI. Check for mistakes.
Comment thread k6/load-test.js
Comment on lines +530 to +545
// Parse duration string manually
let value = 0;
let unit = '';
for (let j = 0; j < duration.length; j++) {
const char = duration[j];
if (char >= '0' && char <= '9') {
value = value * 10 + parseInt(char);
} else {
unit = char;
break;
}
}

if (unit === 's') totalDuration += value;
else if (unit === 'm') totalDuration += value * 60;
else if (unit === 'h') totalDuration += value * 3600;
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duration parsing logic is fragile and only captures the first character of the unit. If the duration string format changes or contains multi-character units (like 'ms'), this will fail. The code should either handle multi-character units or document that only single-character units ('s', 'm', 'h') are supported.

Suggested change
// Parse duration string manually
let value = 0;
let unit = '';
for (let j = 0; j < duration.length; j++) {
const char = duration[j];
if (char >= '0' && char <= '9') {
value = value * 10 + parseInt(char);
} else {
unit = char;
break;
}
}
if (unit === 's') totalDuration += value;
else if (unit === 'm') totalDuration += value * 60;
else if (unit === 'h') totalDuration += value * 3600;
// Parse duration string using regex to support multi-character units
const match = duration.match(/^(\d+)([a-zA-Z]+)$/);
if (!match) continue;
const value = parseInt(match[1], 10);
const unit = match[2];
if (unit === 's') totalDuration += value;
else if (unit === 'm') totalDuration += value * 60;
else if (unit === 'h') totalDuration += value * 3600;
// If you want to support milliseconds, uncomment the following:
// else if (unit === 'ms') totalDuration += value / 1000;
// else continue; // skip unsupported units

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

3 participants