Add load testing job to GitHub Actions CI pipeline [FRE-4931]
This commit is contained in:
69
scripts/load-test/compare-baseline.js
Normal file
69
scripts/load-test/compare-baseline.js
Normal file
@@ -0,0 +1,69 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
async function compareBaseline() {
|
||||
const reportsDir = path.join(__dirname, 'reports');
|
||||
const baselinePath = path.join(reportsDir, 'baseline.json');
|
||||
const currentPath = path.join(reportsDir, 'current.json');
|
||||
|
||||
const baselineThreshold = parseFloat(process.env.BASELINE_THRESHOLD) || 0.1;
|
||||
|
||||
if (!fs.existsSync(baselinePath)) {
|
||||
console.log('No baseline found, creating initial baseline');
|
||||
createBaseline();
|
||||
return;
|
||||
}
|
||||
|
||||
const baseline = JSON.parse(fs.readFileSync(baselinePath, 'utf8'));
|
||||
const current = JSON.parse(fs.readFileSync(currentPath, 'utf8'));
|
||||
|
||||
const avgTimeChange = (current.avgResponseTime - baseline.avgResponseTime) / baseline.avgResponseTime;
|
||||
const successRateChange = current.successRate - baseline.successRate;
|
||||
|
||||
console.log('\n=== Baseline Comparison ===');
|
||||
console.log(`Baseline Avg Response Time: ${baseline.avgResponseTime.toFixed(2)}ms`);
|
||||
console.log(`Current Avg Response Time: ${current.avgResponseTime.toFixed(2)}ms`);
|
||||
console.log(`Change: ${(avgTimeChange * 100).toFixed(2)}%`);
|
||||
console.log(`Baseline Success Rate: ${baseline.successRate.toFixed(2)}%`);
|
||||
console.log(`Current Success Rate: ${current.successRate.toFixed(2)}%`);
|
||||
console.log(`Change: ${successRateChange.toFixed(2)}%`);
|
||||
|
||||
const passed = Math.abs(avgTimeChange) <= baselineThreshold && successRateChange >= -1;
|
||||
|
||||
if (passed) {
|
||||
console.log('\n✓ Performance baseline check PASSED');
|
||||
process.exit(0);
|
||||
} else {
|
||||
console.log('\n✗ Performance baseline check FAILED');
|
||||
if (Math.abs(avgTimeChange) > baselineThreshold) {
|
||||
console.log(` - Response time changed by ${(avgTimeChange * 100).toFixed(2)}% (threshold: ${baselineThreshold * 100}%)`);
|
||||
}
|
||||
if (successRateChange < -1) {
|
||||
console.log(` - Success rate dropped by ${successRateChange.toFixed(2)}%`);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function createBaseline() {
|
||||
const reportsDir = path.join(__dirname, 'reports');
|
||||
const baseline = {
|
||||
avgResponseTime: 100,
|
||||
successRate: 99.0,
|
||||
createdAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
if (!fs.existsSync(reportsDir)) {
|
||||
fs.mkdirSync(reportsDir, { recursive: true });
|
||||
}
|
||||
|
||||
fs.writeFileSync(baselinePath, JSON.stringify(baseline, null, 2));
|
||||
console.log('Initial baseline created');
|
||||
}
|
||||
|
||||
const baselinePath = path.join(__dirname, 'reports', 'baseline.json');
|
||||
if (!fs.existsSync(baselinePath)) {
|
||||
createBaseline();
|
||||
} else {
|
||||
compareBaseline();
|
||||
}
|
||||
Reference in New Issue
Block a user