Skip to content

Commit

Permalink
[ML] Fix flaky Trained Models tests (#125484)
Browse files Browse the repository at this point in the history
* add extra assertion

* prevent extra call on init

* fix stats call
  • Loading branch information
darnautov authored Feb 14, 2022
1 parent 91314e0 commit b51c87f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ export function trainedModelsApiProvider(httpService: HttpService) {
* @param params - Optional query params
*/
getTrainedModelStats(modelId?: string | string[], params?: InferenceStatsQueryParams) {
let model = modelId ?? '_all';
if (Array.isArray(modelId)) {
model = modelId.join(',');
}
const model = (Array.isArray(modelId) ? modelId.join(',') : modelId) || '_all';

return httpService.http<InferenceStatsResponse>({
path: `${apiBasePath}/trained_models/${model}/_stats`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export const ModelsList: FC = () => {

useEffect(
function updateOnTimerRefresh() {
if (!refresh) return;
fetchModelsData();
},
[refresh]
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/functional/apps/ml/model_management/model_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await ml.trainedModels.createTestTrainedModels('classification', 15, true);
await ml.trainedModels.createTestTrainedModels('regression', 15);
await ml.securityUI.loginAsMlPowerUser();
await ml.navigation.navigateToTrainedModels();
});

after(async () => {
Expand Down Expand Up @@ -46,6 +44,7 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await ml.securityUI.loginAsMlPowerUser();
await ml.navigation.navigateToTrainedModels();
await ml.commonUI.waitForRefreshButtonEnabled();
});

after(async () => {
Expand Down Expand Up @@ -173,6 +172,7 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await ml.securityUI.loginAsMlViewer();
await ml.navigation.navigateToTrainedModels();
await ml.commonUI.waitForRefreshButtonEnabled();
});

after(async () => {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/functional/services/ml/common_ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,9 @@ export function MachineLearningCommonUIProvider({
async waitForDatePickerIndicatorLoaded() {
await testSubjects.waitForEnabled('superDatePickerApplyTimeButton');
},

async waitForRefreshButtonEnabled() {
await testSubjects.waitForEnabled('~mlRefreshPageButton');
},
};
}
2 changes: 1 addition & 1 deletion x-pack/test/functional/services/ml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function MachineLearningProvider(context: FtrProviderContext) {
const alerting = MachineLearningAlertingProvider(context, commonUI);
const swimLane = SwimLaneProvider(context);
const trainedModels = TrainedModelsProvider(context, api, commonUI);
const trainedModelsTable = TrainedModelsTableProvider(context);
const trainedModelsTable = TrainedModelsTableProvider(context, commonUI);
const mlNodesPanel = MlNodesPanelProvider(context);

return {
Expand Down
9 changes: 7 additions & 2 deletions x-pack/test/functional/services/ml/trained_models_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { ProvidedType } from '@kbn/test';
import { upperFirst } from 'lodash';

import { WebElementWrapper } from 'test/functional/services/lib/web_element_wrapper';
import { FtrProviderContext } from '../../ftr_provider_context';
import type { FtrProviderContext } from '../../ftr_provider_context';
import type { MlCommonUI } from './common_ui';

export interface TrainedModelRowData {
id: string;
Expand All @@ -20,7 +21,10 @@ export interface TrainedModelRowData {

export type MlTrainedModelsTable = ProvidedType<typeof TrainedModelsTableProvider>;

export function TrainedModelsTableProvider({ getService }: FtrProviderContext) {
export function TrainedModelsTableProvider(
{ getService }: FtrProviderContext,
mlCommonUI: MlCommonUI
) {
const testSubjects = getService('testSubjects');
const retry = getService('retry');

Expand Down Expand Up @@ -218,6 +222,7 @@ export function TrainedModelsTableProvider({ getService }: FtrProviderContext) {
await testSubjects.existOrFail('mlTrainedModelRowDetails', { timeout: 1000 });
}
});
await mlCommonUI.waitForRefreshButtonEnabled();
}

public async assertTabContent(
Expand Down

0 comments on commit b51c87f

Please sign in to comment.