-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fixes a race condition where the ML plugin would be mounted before receiving its first license information update and thus redirecting to a fallback page (Kibana Home, Space-Chooser or Data Visualizer page depending on the setup).
- Loading branch information
Showing
3 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
x-pack/plugins/ml/public/application/license/ml_client_license.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Observable, Subject } from 'rxjs'; | ||
import { ILicense } from '../../../../licensing/common/types'; | ||
|
||
import { MlClientLicense } from './ml_client_license'; | ||
|
||
describe('MlClientLicense', () => { | ||
test('should miss the license update when initialized without postInitFunction', () => { | ||
const mlLicense = new MlClientLicense(); | ||
|
||
// upon instantiation the full license doesn't get set | ||
expect(mlLicense.isFullLicense()).toBe(false); | ||
|
||
const license$ = new Subject(); | ||
|
||
mlLicense.setup(license$ as Observable<ILicense>); | ||
|
||
// if the observable wasn't triggered the full license is still not set | ||
expect(mlLicense.isFullLicense()).toBe(false); | ||
|
||
license$.next({ | ||
check: () => ({ state: 'valid' }), | ||
getFeature: () => ({ isEnabled: true }), | ||
status: 'valid', | ||
}); | ||
|
||
// once the observable triggered the license should be set | ||
expect(mlLicense.isFullLicense()).toBe(true); | ||
}); | ||
|
||
test('should not miss the license update when initialized with postInitFunction', (done) => { | ||
const mlLicense = new MlClientLicense(); | ||
|
||
// upon instantiation the full license doesn't get set | ||
expect(mlLicense.isFullLicense()).toBe(false); | ||
|
||
const license$ = new Subject(); | ||
|
||
mlLicense.setup(license$ as Observable<ILicense>, [ | ||
(license) => { | ||
// when passed in via postInitFunction callback, the license should be valid | ||
// even if the license$ observable gets triggered after this setup. | ||
expect(license.isFullLicense()).toBe(true); | ||
done(); | ||
}, | ||
]); | ||
|
||
license$.next({ | ||
check: () => ({ state: 'valid' }), | ||
getFeature: () => ({ isEnabled: true }), | ||
status: 'valid', | ||
}); | ||
}); | ||
}); |