55 * 2.0.
66 */
77
8- import type { TaskManagerSetupContract } from '@kbn/task-manager-plugin/server/plugin' ;
98import type { CustomTaskInstance } from './sync_private_locations_monitors_task' ;
109import {
1110 SyncPrivateLocationMonitorsTask ,
@@ -84,20 +83,20 @@ describe('SyncPrivateLocationMonitorsTask', () => {
8483 jest . clearAllMocks ( ) ;
8584 task = new SyncPrivateLocationMonitorsTask (
8685 mockServerSetup as any ,
87- mockTaskManager as unknown as TaskManagerSetupContract ,
8886 mockSyntheticsMonitorClient as unknown as SyntheticsMonitorClient
8987 ) ;
9088 mockSoClient . createInternalRepository . mockReturnValue ( mockSoClient as any ) ;
9189 } ) ;
9290
9391 describe ( 'constructor' , ( ) => {
9492 it ( 'should register task definitions correctly' , ( ) => {
93+ task . registerTaskDefinition ( mockTaskManager as any ) ;
9594 expect ( mockTaskManager . registerTaskDefinitions ) . toHaveBeenCalledWith ( {
9695 'Synthetics:Sync-Private-Location-Monitors' : expect . objectContaining ( {
9796 title : 'Synthetics Sync Global Params Task' ,
9897 description :
9998 'This task is executed so that we can sync private location monitors for example when global params are updated' ,
100- timeout : '5m ' ,
99+ timeout : '10m ' ,
101100 maxAttempts : 1 ,
102101 createTaskRunner : expect . any ( Function ) ,
103102 } ) ,
@@ -150,6 +149,7 @@ describe('SyncPrivateLocationMonitorsTask', () => {
150149 expect ( mockSyntheticsMonitorClient . privateLocationAPI . editMonitors ) . not . toHaveBeenCalled ( ) ;
151150 expect ( result . error ) . toBeUndefined ( ) ;
152151 expect ( result . state ) . toEqual ( {
152+ disableAutoSync : false ,
153153 hasAlreadyDoneCleanup : false ,
154154 lastStartedAt : expect . anything ( ) ,
155155 lastTotalParams : 1 ,
@@ -190,6 +190,7 @@ describe('SyncPrivateLocationMonitorsTask', () => {
190190 expect ( task . syncGlobalParams ) . toHaveBeenCalled ( ) ;
191191 expect ( result . error ) . toBeUndefined ( ) ;
192192 expect ( result . state ) . toEqual ( {
193+ disableAutoSync : false ,
193194 lastTotalParams : 1 ,
194195 lastTotalMWs : 1 ,
195196 maxCleanUpRetries : 2 ,
@@ -227,6 +228,7 @@ describe('SyncPrivateLocationMonitorsTask', () => {
227228 ) ;
228229 expect ( result . error ) . toBe ( error ) ;
229230 expect ( result . state ) . toEqual ( {
231+ disableAutoSync : false ,
230232 lastStartedAt : expect . anything ( ) ,
231233 lastTotalParams : 1 ,
232234 lastTotalMWs : 1 ,
@@ -414,7 +416,6 @@ describe('SyncPrivateLocationMonitorsTask', () => {
414416
415417 await task . syncGlobalParams ( {
416418 allPrivateLocations : mockAllPrivateLocations as any ,
417- encryptedSavedObjects : mockEncryptedSoClient as any ,
418419 soClient : mockSoClient as any ,
419420 } ) ;
420421
@@ -445,7 +446,6 @@ describe('SyncPrivateLocationMonitorsTask', () => {
445446 await task . syncGlobalParams ( {
446447 allPrivateLocations : [ ] ,
447448 soClient : mockSoClient as any ,
448- encryptedSavedObjects : mockEncryptedSoClient as any ,
449449 } ) ;
450450
451451 expect ( mockSyntheticsMonitorClient . privateLocationAPI . editMonitors ) . not . toHaveBeenCalled ( ) ;
@@ -506,7 +506,6 @@ describe('SyncPrivateLocationMonitorsTask', () => {
506506 mockSoClient . createPointInTimeFinder = jest . fn ( ) . mockReturnValue ( mockFinder ) ;
507507 task = new SyncPrivateLocationMonitorsTask (
508508 mockServerSetup as any ,
509- mockTaskManager as unknown as TaskManagerSetupContract ,
510509 mockSyntheticsMonitorClient as unknown as SyntheticsMonitorClient
511510 ) ;
512511 } ) ;
@@ -519,10 +518,10 @@ describe('SyncPrivateLocationMonitorsTask', () => {
519518 ) ;
520519 const result = await task . cleanUpDuplicatedPackagePolicies ( mockSoClient as any , { } as any ) ;
521520 expect ( mockFleet . packagePolicyService . delete ) . not . toHaveBeenCalled ( ) ;
522- expect ( result . performSync ) . toBe ( false ) ;
521+ expect ( result . performCleanupSync ) . toBe ( false ) ;
523522 } ) ;
524523
525- it ( 'should delete unexpected policies and set performSync true' , async ( ) => {
524+ it ( 'should delete unexpected policies and set performCleanupSync true' , async ( ) => {
526525 mockFleet . packagePolicyService . fetchAllItemIds . mockResolvedValue (
527526 ( async function * ( ) {
528527 yield [ 'monitor1-loc1-space1' , 'unexpected-policy' ] ;
@@ -535,30 +534,30 @@ describe('SyncPrivateLocationMonitorsTask', () => {
535534 [ 'unexpected-policy' ] ,
536535 { force : true , spaceIds : [ '*' ] }
537536 ) ;
538- expect ( result . performSync ) . toBe ( true ) ;
537+ expect ( result . performCleanupSync ) . toBe ( true ) ;
539538 } ) ;
540539
541- it ( 'should set performSync true if expected policies are missing' , async ( ) => {
540+ it ( 'should set performCleanupSync true if expected policies are missing' , async ( ) => {
542541 mockFleet . packagePolicyService . fetchAllItemIds . mockResolvedValue (
543542 ( async function * ( ) {
544543 yield [ ] ;
545544 } ) ( )
546545 ) ;
547546 const result = await task . cleanUpDuplicatedPackagePolicies ( mockSoClient as any , { } as any ) ;
548- expect ( result . performSync ) . toBe ( true ) ;
547+ expect ( result . performCleanupSync ) . toBe ( true ) ;
549548 } ) ;
550549
551- it ( 'should handle errors gracefully and return performSync ' , async ( ) => {
550+ it ( 'should handle errors gracefully and return performCleanupSync ' , async ( ) => {
552551 mockFleet . packagePolicyService . fetchAllItemIds . mockRejectedValue ( new Error ( 'fail' ) ) ;
553552 const result = await task . cleanUpDuplicatedPackagePolicies ( mockSoClient as any , { } as any ) ;
554553 expect ( mockLogger . error ) . toHaveBeenCalled ( ) ;
555- expect ( result ) . toHaveProperty ( 'performSync ' ) ;
554+ expect ( result ) . toHaveProperty ( 'performCleanupSync ' ) ;
556555 } ) ;
557556
558557 it ( 'should skip cleanup if hasAlreadyDoneCleanup is true' , async ( ) => {
559558 const state = { hasAlreadyDoneCleanup : true , maxCleanUpRetries : 3 } ;
560559 const result = await task . cleanUpDuplicatedPackagePolicies ( mockSoClient as any , state as any ) ;
561- expect ( result . performSync ) . toBe ( false ) ;
560+ expect ( result . performCleanupSync ) . toBe ( false ) ;
562561 expect ( mockLogger . debug ) . toHaveBeenCalledWith (
563562 '[SyncPrivateLocationMonitorsTask] Skipping cleanup of duplicated package policies as it has already been done once'
564563 ) ;
@@ -567,7 +566,7 @@ describe('SyncPrivateLocationMonitorsTask', () => {
567566 it ( 'should skip cleanup if maxCleanUpRetries is 0 or less' , async ( ) => {
568567 const state = { hasAlreadyDoneCleanup : false , maxCleanUpRetries : 0 } ;
569568 const result = await task . cleanUpDuplicatedPackagePolicies ( mockSoClient as any , state as any ) ;
570- expect ( result . performSync ) . toBe ( false ) ;
569+ expect ( result . performCleanupSync ) . toBe ( false ) ;
571570 expect ( state . hasAlreadyDoneCleanup ) . toBe ( true ) ;
572571 expect ( state . maxCleanUpRetries ) . toBe ( 3 ) ;
573572 expect ( mockLogger . debug ) . toHaveBeenCalledWith (
@@ -581,7 +580,7 @@ describe('SyncPrivateLocationMonitorsTask', () => {
581580 const state = { hasAlreadyDoneCleanup : false , maxCleanUpRetries : 2 } ;
582581 const result = await task . cleanUpDuplicatedPackagePolicies ( mockSoClient as any , state as any ) ;
583582 expect ( state . maxCleanUpRetries ) . toBe ( 1 ) ;
584- expect ( result ) . toHaveProperty ( 'performSync ' ) ;
583+ expect ( result ) . toHaveProperty ( 'performCleanupSync ' ) ;
585584 // Call again to reach 0
586585 await task . cleanUpDuplicatedPackagePolicies ( mockSoClient as any , state as any ) ;
587586 expect ( state . hasAlreadyDoneCleanup ) . toBe ( true ) ;
0 commit comments