File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
tests/periodic-test/time-is-synchronized Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -87,16 +87,17 @@ try {
8787 console . log ( "ℹ️ running command" ) ;
8888
8989 console . log ( "ℹ️ starting command" ) ;
90- const localDate = new Date ( ) . getTime ( ) / 1000 ;
90+ const localDateStart = new Date ( ) . getTime ( ) / 1000 ;
9191 const date = await sandbox . commands . run ( "date +%s%3N" ) ;
92- console . log ( "localDate" , localDate ) ;
93-
94- console . log ( "date" , date . stdout ) ;
92+ const localDateEnd = new Date ( ) . getTime ( ) / 1000 ;
9593 const dateUnix = parseFloat ( date . stdout ) / 1000 ;
96- console . log ( "ℹ️ comparing dates" , dateUnix , localDate ) ;
9794
98- // compare the dates, should be within 2 second
99- if ( Math . abs ( dateUnix - localDate ) > 2 ) {
95+ console . log ( "local date - start of request" , localDateStart ) ;
96+ console . log ( "local date - end of request" , localDateEnd ) ;
97+ console . log ( "sandbox date" , dateUnix ) ;
98+
99+ // check if the diff between sandbox time and local time is less than 1 second (taking into consideration the request latency)
100+ if ( dateUnix < localDateStart - 1 || dateUnix > localDateEnd + 1 ) {
100101 throw new Error ( "❌ Date is not synchronized" ) ;
101102 }
102103
You can’t perform that action at this time.
0 commit comments