mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
test: Add baseline memory test (#19102)
This commit is contained in:
@@ -42,6 +42,7 @@ const BASE_ENV: Record<string, string> = {
|
|||||||
E2E_TESTS: 'false',
|
E2E_TESTS: 'false',
|
||||||
QUEUE_HEALTH_CHECK_ACTIVE: 'true',
|
QUEUE_HEALTH_CHECK_ACTIVE: 'true',
|
||||||
N8N_DIAGNOSTICS_ENABLED: 'false',
|
N8N_DIAGNOSTICS_ENABLED: 'false',
|
||||||
|
N8N_METRICS: 'true',
|
||||||
N8N_RUNNERS_ENABLED: 'true',
|
N8N_RUNNERS_ENABLED: 'true',
|
||||||
NODE_ENV: 'development', // If this is set to test, the n8n container will not start, insights module is not found??
|
NODE_ENV: 'development', // If this is set to test, the n8n container will not start, insights module is not found??
|
||||||
N8N_LICENSE_TENANT_ID: process.env.N8N_LICENSE_TENANT_ID ?? '1001',
|
N8N_LICENSE_TENANT_ID: process.env.N8N_LICENSE_TENANT_ID ?? '1001',
|
||||||
|
|||||||
@@ -71,5 +71,5 @@ export default defineConfig({
|
|||||||
currentsReporter(currentsConfig),
|
currentsReporter(currentsConfig),
|
||||||
['./reporters/metrics-reporter.ts'],
|
['./reporters/metrics-reporter.ts'],
|
||||||
]
|
]
|
||||||
: [['html'], ['./reporters/metrics-reporter.ts']],
|
: [['html'], ['./reporters/metrics-reporter.ts'], ['list']],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { test, expect } from '../../fixtures/cloud';
|
||||||
|
import { attachMetric, pollMemoryMetric } from '../../utils/performance-helper';
|
||||||
|
|
||||||
|
test.describe('Memory Consumption', () => {
|
||||||
|
const CONTAINER_STABILIZATION_TIME = 20000;
|
||||||
|
const POLL_MEMORY_DURATION = 30000;
|
||||||
|
const STARTER_PLAN_MEMORY_LIMIT = 768;
|
||||||
|
|
||||||
|
test('Memory consumption baseline with starter plan resources @cloud:starter', async ({
|
||||||
|
cloudContainer,
|
||||||
|
}, testInfo) => {
|
||||||
|
// Wait for container to stabilize
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, CONTAINER_STABILIZATION_TIME));
|
||||||
|
|
||||||
|
// Poll memory metric for 30 seconds to get baseline
|
||||||
|
const averageMemoryBytes = await pollMemoryMetric(
|
||||||
|
cloudContainer.baseUrl,
|
||||||
|
POLL_MEMORY_DURATION,
|
||||||
|
1000,
|
||||||
|
);
|
||||||
|
const averageMemoryMB = averageMemoryBytes / 1024 / 1024;
|
||||||
|
|
||||||
|
await attachMetric(testInfo, 'memory-consumption-baseline', averageMemoryMB, 'MB');
|
||||||
|
|
||||||
|
// Verify memory is within starter plan limits (768MB)
|
||||||
|
expect(averageMemoryMB).toBeLessThan(STARTER_PLAN_MEMORY_LIMIT);
|
||||||
|
expect(averageMemoryMB).toBeGreaterThan(100);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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
|
* Attach a performance metric for collection by the metrics reporter
|
||||||
* @param testInfo - The Playwright TestInfo object
|
* @param testInfo - The Playwright TestInfo object
|
||||||
|
|||||||
Reference in New Issue
Block a user