@@ -583,8 +583,72 @@ describe('Indices Metadata - IndicesMetadataService', () => {
583583 it ( 'should handle receiver errors during publishIndicesMetadata' , async ( ) => {
584584 const error = new Error ( 'Elasticsearch error' ) ;
585585 receiver . getIndices . mockRejectedValue ( error ) ;
586+ receiver . getDataStreams . mockResolvedValue ( mockDataStreams ) ;
587+ receiver . getIndexTemplatesStats . mockResolvedValue ( mockIndexTemplates ) ;
588+
589+ await service [ 'publishIndicesMetadata' ] ( ) ; // eslint-disable-line dot-notation
590+
591+ expect ( logger . error ) . toHaveBeenCalledWith ( 'Error fetching indices metadata' , { error } ) ;
592+ expect ( logger . debug ) . toHaveBeenCalledWith (
593+ 'Skipping indices metadata publish due to fetch errors'
594+ ) ;
595+ expect ( sender . reportEBT ) . not . toHaveBeenCalled ( ) ;
596+ } ) ;
597+
598+ it ( 'should handle partial receiver errors during publishIndicesMetadata' , async ( ) => {
599+ const error = new Error ( 'DataStream error' ) ;
600+ receiver . getIndices . mockResolvedValue ( mockIndexSettings ) ;
601+ receiver . getDataStreams . mockRejectedValue ( error ) ;
602+ receiver . getIndexTemplatesStats . mockResolvedValue ( mockIndexTemplates ) ;
603+
604+ await service [ 'publishIndicesMetadata' ] ( ) ; // eslint-disable-line dot-notation
605+
606+ expect ( logger . error ) . toHaveBeenCalledWith ( 'Error fetching indices metadata' , { error } ) ;
607+ expect ( logger . debug ) . toHaveBeenCalledWith (
608+ 'Skipping indices metadata publish due to fetch errors'
609+ ) ;
610+ expect ( sender . reportEBT ) . not . toHaveBeenCalled ( ) ;
611+ } ) ;
612+
613+ it ( 'should handle all receiver methods failing during publishIndicesMetadata' , async ( ) => {
614+ const indicesError = new Error ( 'Indices error' ) ;
615+ const dataStreamError = new Error ( 'DataStream error' ) ;
616+ const templatesError = new Error ( 'Templates error' ) ;
617+
618+ receiver . getIndices . mockRejectedValue ( indicesError ) ;
619+ receiver . getDataStreams . mockRejectedValue ( dataStreamError ) ;
620+ receiver . getIndexTemplatesStats . mockRejectedValue ( templatesError ) ;
586621
587- await expect ( service [ 'publishIndicesMetadata' ] ( ) ) . rejects . toThrow ( 'Elasticsearch error' ) ; // eslint-disable-line dot-notation
622+ await service [ 'publishIndicesMetadata' ] ( ) ; // eslint-disable-line dot-notation
623+
624+ expect ( logger . error ) . toHaveBeenCalledWith ( 'Error fetching indices metadata' , {
625+ error : indicesError ,
626+ } ) ;
627+ expect ( logger . debug ) . toHaveBeenCalledWith (
628+ 'Skipping indices metadata publish due to fetch errors'
629+ ) ;
630+ expect ( sender . reportEBT ) . not . toHaveBeenCalled ( ) ;
631+ } ) ;
632+
633+ it ( 'should continue processing when receiver methods return empty results' , async ( ) => {
634+ receiver . getIndices . mockResolvedValue ( [ ] ) ;
635+ receiver . getDataStreams . mockResolvedValue ( [ ] ) ;
636+ receiver . getIndexTemplatesStats . mockResolvedValue ( [ ] ) ;
637+ receiver . getIndicesStats . mockImplementation ( async function * ( ) {
638+ // yield nothing
639+ } ) ;
640+ receiver . isIlmStatsAvailable . mockResolvedValue ( false ) ;
641+ receiver . getIlmsPolicies . mockImplementation ( async function * ( ) {
642+ // yield nothing
643+ } ) ;
644+
645+ await service [ 'publishIndicesMetadata' ] ( ) ; // eslint-disable-line dot-notation
646+
647+ expect ( receiver . getIndices ) . toHaveBeenCalled ( ) ;
648+ expect ( receiver . getDataStreams ) . toHaveBeenCalled ( ) ;
649+ expect ( receiver . getIndexTemplatesStats ) . toHaveBeenCalled ( ) ;
650+ expect ( sender . reportEBT ) . toHaveBeenCalledTimes ( 5 ) ; // datastreams, indices settings, indices stats, ILM policies (empty), templates
651+ expect ( logger . debug ) . toHaveBeenCalledWith ( 'ILM explain API is not available' ) ;
588652 } ) ;
589653
590654 it ( 'should handle sender errors during publishDatastreamsStats' , ( ) => {
0 commit comments