@@ -830,6 +830,7 @@ describe('Actor', () => {
830830
831831 describe ( 'Actor.reboot()' , ( ) => {
832832 const { actId, runId } = globalOptions ;
833+ const { run } = runConfigs ;
833834
834835 beforeEach ( ( ) => {
835836 process . env [ APIFY_ENV_VARS . IS_AT_HOME ] = '1' ;
@@ -844,19 +845,11 @@ describe('Actor', () => {
844845 jest . restoreAllMocks ( ) ;
845846 } ) ;
846847
847- test ( 'metamorphs to the same actor' , async ( ) => {
848- const metamorphSpy = jest . spyOn ( Actor . prototype , 'metamorph' ) ;
849- metamorphSpy . mockResolvedValueOnce ( ) ;
850-
851- await Actor . reboot ( ) ;
852-
853- expect ( metamorphSpy ) . toBeCalledTimes ( 1 ) ;
854- expect ( metamorphSpy ) . toBeCalledWith ( actId ) ;
855- } ) ;
856-
857- test ( 'reboot waits for persistState/migrating listeners before morphing' , async ( ) => {
858- const metamorphSpy = jest . spyOn ( Actor . prototype , 'metamorph' ) ;
859- metamorphSpy . mockResolvedValueOnce ( ) ;
848+ test ( 'reboot waits for persistState/migrating listeners before rebooting' , async ( ) => {
849+ const rebootMock = jest . fn ( ) ;
850+ rebootMock . mockResolvedValueOnce ( run ) ;
851+ const rebootSpy = jest . spyOn ( ApifyClient . prototype , 'run' ) ;
852+ rebootSpy . mockReturnValueOnce ( { reboot : rebootMock } as any ) ;
860853
861854 const persistenceStore = [ ] ;
862855
@@ -872,7 +865,7 @@ describe('Actor', () => {
872865 events . on ( EventType . PERSIST_STATE , persistStateSpy ) ;
873866 events . on ( EventType . MIGRATING , migratingSpy ) ;
874867
875- await Actor . reboot ( ) ;
868+ await Actor . reboot ( { customAfterSleepMillis : 1 } ) ;
876869
877870 events . off ( EventType . PERSIST_STATE , persistStateSpy ) ;
878871 events . off ( EventType . MIGRATING , migratingSpy ) ;
@@ -883,6 +876,9 @@ describe('Actor', () => {
883876
884877 // Do the listeners finish?
885878 expect ( persistenceStore . length ) . toBe ( 2 ) ;
879+
880+ // Did the client's reboot method get called?
881+ expect ( rebootMock ) . toBeCalledTimes ( 1 ) ;
886882 } ) ;
887883 } ) ;
888884
0 commit comments