mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 03:12:15 +00:00
test: Add baseline memory test (#19102)
This commit is contained in:
@@ -29,6 +29,45 @@ export async function getAllPerformanceMetrics(page: Page) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls the memory metric from Prometheus endpoint and calculates average
|
||||
* @param baseUrl - The base URL of the n8n instance
|
||||
* @param durationMs - How long to poll in milliseconds
|
||||
* @param intervalMs - Interval between polls in milliseconds
|
||||
* @returns Average memory consumption in bytes
|
||||
*/
|
||||
export async function pollMemoryMetric(
|
||||
baseUrl: string,
|
||||
durationMs: number = 30000,
|
||||
intervalMs: number = 1000,
|
||||
): Promise<number> {
|
||||
const samples: number[] = [];
|
||||
const startTime = Date.now();
|
||||
|
||||
while (Date.now() - startTime < durationMs) {
|
||||
try {
|
||||
const response = await fetch(`${baseUrl}/metrics`);
|
||||
const metricsText = await response.text();
|
||||
|
||||
const memoryMatch = metricsText.match(/n8n_process_resident_memory_bytes\s+(\d+(?:\.\d+)?)/);
|
||||
if (memoryMatch) {
|
||||
const memoryBytes = parseFloat(memoryMatch[1]);
|
||||
samples.push(memoryBytes);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error polling memory metric:', error);
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
||||
}
|
||||
|
||||
if (samples.length === 0) {
|
||||
throw new Error('No memory samples collected');
|
||||
}
|
||||
|
||||
return samples.reduce((sum, sample) => sum + sample, 0) / samples.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a performance metric for collection by the metrics reporter
|
||||
* @param testInfo - The Playwright TestInfo object
|
||||
|
||||
Reference in New Issue
Block a user