Skip to content

Commit 5effc10

Browse files
committed
Fix: Add retry logic for all flaky tests and remove firefox/webkit
1 parent 268a0ba commit 5effc10

7 files changed

Lines changed: 45 additions & 18 deletions

File tree

.github/workflows/test-and-deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
run: |
3636
npx playwright test --project=chromium \
3737
--retries=2 \
38+
--timeout=90000 \
3839
--reporter=html,list
3940
continue-on-error: true
4041

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
"main": "index.js",
55
"scripts": {
66
"test": "playwright test",
7-
"test:report": "playwright test --reporter=html",
8-
"upload:report": "ts-node scripts/uploadReportToS3.ts",
9-
"test:s3": "npm run test:report && npm run upload:report",
10-
"test:all": "npm test && npm run upload:report"
7+
"test:all": "npm run test:core && npm run test:integration && npm run test:s3",
8+
"test:core": "playwright test --grep-invert \"S3 Reports\" --grep-invert \"Tests de integración\" --grep-invert \"CloudWatch muestra métricas de invocaciones\"",
9+
"test:integration": "playwright test --grep \"Tests de integración con SQS y DynamoDB\" --timeout=60000 --retries=1",
10+
"test:s3": "playwright test tests/S3Reports.spec.ts",
11+
"test:cloudwatch": "playwright test --grep \"CloudWatch muestra métricas de invocaciones\"",
12+
"test:report": "playwright test --reporter=html && playwright show-report"
13+
1114
},
1215
"keywords": [],
1316
"author": "",

playwright.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default defineConfig({
3939
use: { ...devices["Desktop Chrome"] },
4040
},
4141

42-
{
42+
/*{
4343
name: "firefox",
4444
use: { ...devices["Desktop Firefox"] },
4545
},
@@ -48,7 +48,7 @@ export default defineConfig({
4848
name: "webkit",
4949
use: { ...devices["Desktop Safari"] },
5050
},
51-
51+
*/
5252
/* Test against mobile viewports. */
5353
// {
5454
// name: 'Mobile Chrome',

tests/DynamoCity.spec.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ test("Test con ciudad vacía en DynamoDB", async () => {
4040
});
4141

4242
test("Simulación de concurrencia - 10 ciudades INVOCAR LAMBDA", async () => {
43+
test.setTimeout(120000);
44+
4345
const ciudades = [
4446
"Jaén",
4547
"Bagua Grande",
@@ -52,25 +54,46 @@ test("Simulación de concurrencia - 10 ciudades INVOCAR LAMBDA", async () => {
5254
"Cuzco",
5355
"Tacna",
5456
];
57+
let resultados: any[];
58+
59+
await test.step("1. Limpiar DynamoDB", async () => {
60+
await Promise.all(ciudades.map((c) => DynamoDBHelper.deleteItem(c)));
61+
await new Promise((resolve) => setTimeout(resolve, 2000));
62+
console.log("✅ DynamoDB limpio para todas las ciudades");
63+
});
5564

56-
await test.step("1. Invocar Lambda para 10 ciudades", async () => {
65+
await test.step("2. Invocar Lambda para 10 ciudades", async () => {
5766
const lambdaInvoker = new LambdaInvoker();
5867
const promesas = ciudades.map((ciudad) =>
5968
lambdaInvoker.invokeLambda("Clima", { ciudad }),
6069
);
61-
await Promise.all(promesas);
62-
console.log("✅ Lambdas invocadas");
70+
resultados = await Promise.all(promesas);
71+
console.log("✅ Todas las invocaciones completadas");
6372
});
6473

65-
await test.step("2. Esperar procesamiento", async () => {
66-
await new Promise((resolve) => setTimeout(resolve, 5000));
74+
await test.step("3. Esperar propagación (15 segundos)", async () => {
75+
await new Promise((resolve) => setTimeout(resolve, 15000)); // ✅ 15 segundos
76+
console.log("✅ Esperando propagación...");
6777
});
6878

69-
await test.step("3. Verificar en DynamoDB", async () => {
79+
await test.step("4. Verificar en DynamoDB con reintentos", async () => {
7080
for (const ciudad of ciudades) {
71-
const result = await DynamoDBHelper.getItem(ciudad);
81+
let result = null;
82+
83+
// ✅ 10 reintentos de 2 segundos cada uno
84+
for (let i = 0; i < 10; i++) {
85+
result = await DynamoDBHelper.getItem(ciudad);
86+
if (result) break;
87+
88+
if (i < 9) {
89+
console.log(`⏳ ${ciudad}: Intento ${i + 1}/10`);
90+
await new Promise((resolve) => setTimeout(resolve, 2000));
91+
}
92+
}
93+
7294
expect(result).toBeDefined();
73-
console.log(`✅ ${ciudad}: Verificado`);
95+
expect(result.ciudad).toBe(ciudad);
96+
console.log(`✅ ${ciudad}: OK`);
7497
}
7598
});
7699
});

tests/LambdaClima.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test.describe.serial("Tests de integración con SQS y DynamoDB", () => {
4949

5050
for (const ciudad of ciudadesReales) {
5151
test(`Procesar ciudad válida: ${ciudad}`, async () => {
52-
test.setTimeout(45000);
52+
test.setTimeout(60000);
5353

5454
let messageId: string;
5555
let mensajeResultado: any;

utils/LambdaClimaHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class LambdaClimaHelper {
3838
const mensajeResultado = await SQSHelper.waitForMessage(
3939
CONFIG.SQS_RESULTS_URL,
4040
(msg) => msg.ciudad?.toLowerCase() === ciudad.toLowerCase(),
41-
10,
41+
15,
4242
);
4343

4444
// 4. Obtener de DynamoDB con reintentos
@@ -51,7 +51,7 @@ export class LambdaClimaHelper {
5151

5252
return {
5353
messageId,
54-
mensajeResultado, // ✅ YA NO HAY JSON.parse()
54+
mensajeResultado,
5555
dbItem,
5656
};
5757
}

utils/TestConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const CONFIG = {
1616
API_GATEWAY_URL: process.env.API_GATEWAY_URL!,
1717

1818
// Polling
19-
MAX_POLL_ATTEMPTS: 10,
19+
MAX_POLL_ATTEMPTS: 15,
2020
POLL_INTERVAL_MS: 2000,
2121
SQS_WAIT_TIME_SECONDS: 5,
2222
SQS_MAX_MESSAGES: 10,

0 commit comments

Comments
 (0)