@@ -833,4 +833,79 @@ describe('index.test', () => {
833833
834834 jest . restoreAllMocks ( ) ;
835835 } ) ;
836+
837+ test ( 'scheduledRefreshTimeZones option' , async ( ) => {
838+ jest . spyOn (
839+ CubejsServerCoreOpen . prototype ,
840+ 'isReadyForQueryProcessing' ,
841+ ) . mockImplementation (
842+ ( ) => true ,
843+ ) ;
844+
845+ const timeoutKiller = withTimeout (
846+ ( ) => {
847+ throw new Error ( 'scheduledRefreshTimeZones was not called' ) ;
848+ } ,
849+ 3 * 1000 ,
850+ ) ;
851+
852+ let counter = 0 ;
853+
854+ const cubejsServerCore = new CubejsServerCoreOpen ( {
855+ dbType : 'mysql' ,
856+ apiSecret : 'secret' ,
857+ // 250ms
858+ scheduledRefreshTimer : 1 ,
859+ scheduledRefreshConcurrency : 1 ,
860+ scheduledRefreshContexts : async ( ) => [
861+ {
862+ securityContext : {
863+ appid : 'test1' ,
864+ u : {
865+ prop1 : 'value1'
866+ }
867+ }
868+ } ,
869+ // securityContext is required in typings, but can be empty in user-space
870+ < any > {
871+ // Renamed to securityContext, let's test that it migrate automatically
872+ authInfo : {
873+ appid : 'test2' ,
874+ u : {
875+ prop2 : 'value2'
876+ }
877+ } ,
878+ } ,
879+ // Null is a default placeholder
880+ null
881+ ] ,
882+ scheduledRefreshTimeZones : async ( ctx ) => {
883+ counter ++ ;
884+ if ( counter === 1 ) {
885+ expect ( ctx . securityContext ) . toEqual ( { appid : 'test1' , u : { prop1 : 'value1' } } ) ;
886+ return [ 'Europe/Kyiv' ] ;
887+ } else if ( counter === 2 ) {
888+ expect ( ctx . securityContext ) . toEqual ( { appid : 'test2' , u : { prop2 : 'value2' } } ) ;
889+ return [ 'Europe/London' ] ;
890+ } else if ( counter === 3 ) {
891+ expect ( ctx . securityContext ) . toEqual ( undefined ) ;
892+
893+ // Kill the timer after processing all 3 test contexts
894+ await timeoutKiller . cancel ( ) ;
895+
896+ return [ 'America/Los_Angeles' ] ;
897+ }
898+
899+ return [ 'Europe/Kyiv' , 'Europe/London' , 'America/Los_Angeles' ] ;
900+ }
901+ } ) ;
902+
903+ await timeoutKiller ;
904+
905+ expect ( cubejsServerCore ) . toBeInstanceOf ( CubejsServerCoreOpen ) ;
906+ expect ( counter ) . toBe ( 3 ) ;
907+
908+ await cubejsServerCore . beforeShutdown ( ) ;
909+ await cubejsServerCore . shutdown ( ) ;
910+ } ) ;
836911} ) ;
0 commit comments