diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/_state_machine_package_install.test.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/_state_machine_package_install.test.ts index dfd6cce6b91bc..61ba44d078dd8 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/_state_machine_package_install.test.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/_state_machine_package_install.test.ts @@ -41,7 +41,11 @@ import { installIndexTemplatesAndPipelines } from '../install_index_template_pip import { createArchiveIteratorFromMap } from '../../archive/archive_iterator'; import { handleState } from './state_machine'; -import { _stateMachineInstallPackage } from './_state_machine_package_install'; +import { + _stateMachineInstallPackage, + regularStatesDefinition, + streamingStatesDefinition, +} from './_state_machine_package_install'; import { cleanupLatestExecutedState } from './steps'; jest.mock('./state_machine'); @@ -347,3 +351,24 @@ describe('_stateMachineInstallPackage', () => { await expect(installPromise).rejects.toThrowError(PackageSavedObjectConflictError); }); }); + +describe('State machine parity', () => { + it('should have matching isAsync flags for common states in both regularStatesDefinition and streamingStatesDefinition', () => { + const commonStates = [ + 'create_restart_installation', + 'install_kibana_assets', + 'save_archive_entries_from_assets_map', + 'save_knowledge_base', + 'update_so', + ] as const; + + commonStates.forEach((stateName) => { + const regularState = regularStatesDefinition[stateName]; + const streamingState = streamingStatesDefinition[stateName]; + + if (regularState && streamingState) { + expect(regularState.isAsync).toEqual(streamingState.isAsync); + } + }); + }); +}); diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/_state_machine_package_install.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/_state_machine_package_install.ts index 35b7eca5c0bdd..c154514ec7fa7 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/_state_machine_package_install.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/_state_machine_package_install.ts @@ -90,7 +90,7 @@ export interface InstallContext extends StateContext { /** * This data structure defines the sequence of the states and the transitions */ -const regularStatesDefinition: StateMachineStates = { +export const regularStatesDefinition: StateMachineStates = { create_restart_installation: { nextState: INSTALL_STATES.INSTALL_PRECHECK, onTransition: stepCreateRestartInstallation, @@ -182,7 +182,7 @@ const regularStatesDefinition: StateMachineStates = { }, }; -const streamingStatesDefinition: StateMachineStates = { +export const streamingStatesDefinition: StateMachineStates = { create_restart_installation: { nextState: INSTALL_STATES.INSTALL_KIBANA_ASSETS, onTransition: stepCreateRestartInstallation, @@ -204,6 +204,7 @@ const streamingStatesDefinition: StateMachineStates = { onTransition: stepSaveKnowledgeBase, nextState: INSTALL_STATES.UPDATE_SO, onPostTransition: updateLatestExecutedState, + isAsync: true, // Knowledge base indexing runs in background }, update_so: { onPreTransition: cleanUpUnusedKibanaAssetsStep,