@@ -40,6 +40,8 @@ test("Test con ciudad vacía en DynamoDB", async () => {
4040} ) ;
4141
4242test ( "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} ) ;
0 commit comments