@@ -3,7 +3,11 @@ const Table = require('cli-table3');
33var { constants } = require ( './constants' ) ;
44
55var INTERVAL = 2000
6- const MAX_INTERVAL = 512000
6+ const MAX_EXPONENTIAL_INTERVAL = 512000 // 512 seconds (8.5 minutes)
7+ const FIXED_INTERVAL = 60000 // 1 minute in milliseconds
8+ const MAX_INTERVAL = 1800000 ; // 30 minutes in milliseconds
9+ var CURRENT_TIME = 0
10+ var FLAG = 0
711
812async function shortPolling ( buildId , retries = 0 , options ) {
913 await axios . get ( new URL ( '?buildId=' + buildId , constants [ options . env ] . BUILD_STATUS_URL ) . href , {
@@ -28,16 +32,18 @@ async function shortPolling(buildId, retries = 0, options) {
2832 import ( 'chalk' ) . then ( ( chalk ) => {
2933 const table = new Table ( {
3034 head : [
35+ { content : chalk . default . white ( 'Sr. Number' ) , hAlign : 'center' } ,
3136 { content : chalk . default . white ( 'Story' ) , hAlign : 'center' } ,
3237 { content : chalk . default . white ( 'Mis-match %' ) , hAlign : 'center' } ,
3338 ]
3439 } ) ;
35- response . data . screenshots . forEach ( screenshot => {
36- let mismatch = screenshot . mismatchPercentage
40+ response . data . screenshots . forEach ( ( screenshot , index ) => {
41+ let mismatch = screenshot . mismatchPercentage ;
3742 table . push ( [
43+ chalk . default . yellow ( index + 1 ) ,
3844 chalk . default . yellow ( screenshot . storyName ) ,
3945 mismatch > 0 ? chalk . default . red ( mismatch ) : chalk . default . green ( mismatch )
40- ] )
46+ ] ) ;
4147 } ) ;
4248 console . log ( table . toString ( ) ) ;
4349
@@ -55,19 +61,26 @@ async function shortPolling(buildId, retries = 0, options) {
5561 return ;
5662 } else {
5763 if ( response . data . screenshots && response . data . screenshots . length > 0 ) {
58- // TODO: show Screenshots processed current/total
64+ // TODO: show Screenshots processed current/total
5965 console . log ( '[smartui] Screenshots compared: ' , response . data . screenshots . length )
6066 }
6167 }
6268 }
63-
64- // Double the INTERVAL, up to the maximum INTERVAL of 512 secs (so ~15 mins in total)
65- INTERVAL = Math . min ( INTERVAL * 2 , MAX_INTERVAL ) ;
66- if ( INTERVAL == MAX_INTERVAL ) {
69+
70+ CURRENT_TIME = CURRENT_TIME + INTERVAL
71+ if ( CURRENT_TIME >= MAX_INTERVAL ) {
6772 console . log ( '[smartui] Please check the build status on LambdaTest SmartUI.' ) ;
6873 return ;
6974 }
7075
76+ // Adjust the interval
77+ if ( Math . min ( INTERVAL * 2 , MAX_EXPONENTIAL_INTERVAL ) < MAX_EXPONENTIAL_INTERVAL && FLAG == 0 ) {
78+ INTERVAL = Math . min ( INTERVAL * 2 , MAX_EXPONENTIAL_INTERVAL ) ;
79+ } else {
80+ FLAG = 1
81+ INTERVAL = FIXED_INTERVAL ; // Switch to fixed interval after reaching 256 seconds
82+ }
83+
7184 setTimeout ( function ( ) {
7285 shortPolling ( buildId , 0 , options )
7386 } , INTERVAL ) ;
0 commit comments