mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Simplify and reduce flakiness of license.public (#215874)
## Summary * Factorise logic to fetch latest license. * Add an extra `manualRefresh` step, to ensure we get the latest emission. Aims at tackling [latest failures](https://github.com/elastic/kibana/issues/53575#issuecomment-2751034614) on licensing tests.
This commit is contained in:
parent
31ea22e207
commit
359374e78f
1 changed files with 47 additions and 62 deletions
|
@ -6,8 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import expect from '@kbn/expect';
|
import expect from '@kbn/expect';
|
||||||
import { LicensingPluginSetup } from '@kbn/licensing-plugin/public';
|
import type { ILicense, LicensingPluginStart } from '@kbn/licensing-plugin/public';
|
||||||
import { FtrProviderContext } from '../services';
|
import type { FtrProviderContext } from '../services';
|
||||||
import { createScenario } from '../scenario';
|
import { createScenario } from '../scenario';
|
||||||
import '@kbn/core-provider-plugin/types';
|
import '@kbn/core-provider-plugin/types';
|
||||||
|
|
||||||
|
@ -16,78 +16,63 @@ export default function (ftrContext: FtrProviderContext) {
|
||||||
const { getService } = ftrContext;
|
const { getService } = ftrContext;
|
||||||
const testSubjects = getService('testSubjects');
|
const testSubjects = getService('testSubjects');
|
||||||
const browser = getService('browser');
|
const browser = getService('browser');
|
||||||
|
|
||||||
const scenario = createScenario(ftrContext);
|
const scenario = createScenario(ftrContext);
|
||||||
|
|
||||||
|
const fetchLatestLicense = async (): Promise<ILicense> => {
|
||||||
|
// make sure license ids are aligned between ES and Kibana
|
||||||
|
await scenario.waitForPluginToDetectLicenseUpdate();
|
||||||
|
|
||||||
|
return await browser.executeAsync(async function refreshAndFetchLicense(cb) {
|
||||||
|
const {
|
||||||
|
start: { core, plugins },
|
||||||
|
testUtils,
|
||||||
|
} = window._coreProvider;
|
||||||
|
const licensing: LicensingPluginStart = plugins.licensing;
|
||||||
|
|
||||||
|
// this call enforces signature check to detect license update and causes license re-fetch
|
||||||
|
await core.http.get('/');
|
||||||
|
|
||||||
|
// trigger a manual refresh, just to be sure
|
||||||
|
await licensing.refresh();
|
||||||
|
|
||||||
|
// wait a bit to make sure any older values have passed through the replay(1)
|
||||||
|
await testUtils.delay(1000);
|
||||||
|
|
||||||
|
cb(await licensing.getLicense());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
describe('changes in license types', () => {
|
describe('changes in license types', () => {
|
||||||
after(async () => {
|
before(async function setup() {
|
||||||
|
await scenario.setup();
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async function teardown() {
|
||||||
await scenario.teardown();
|
await scenario.teardown();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('provides changes in license types', async () => {
|
it('are reflected in the start contract', async function updateAndCheckLicense() {
|
||||||
await scenario.setup();
|
// fetch default license
|
||||||
await scenario.waitForPluginToDetectLicenseUpdate();
|
let license = await fetchLatestLicense();
|
||||||
|
expect(license.type).to.be('basic');
|
||||||
|
|
||||||
expect(
|
// ensure consecutive fetch still yields 'basic'
|
||||||
await browser.executeAsync(async (cb) => {
|
license = await fetchLatestLicense();
|
||||||
const { setup, testUtils } = window._coreProvider;
|
expect(license.type).to.be('basic');
|
||||||
// this call enforces signature check to detect license update
|
|
||||||
// and causes license re-fetch
|
|
||||||
await setup.core.http.get('/');
|
|
||||||
await testUtils.delay(1000);
|
|
||||||
|
|
||||||
const licensing: LicensingPluginSetup = setup.plugins.licensing;
|
|
||||||
licensing.license$.subscribe((license) => cb(license.type));
|
|
||||||
})
|
|
||||||
).to.be('basic');
|
|
||||||
|
|
||||||
// license hasn't changed
|
|
||||||
await scenario.waitForPluginToDetectLicenseUpdate();
|
|
||||||
|
|
||||||
expect(
|
|
||||||
await browser.executeAsync(async (cb) => {
|
|
||||||
const { setup, testUtils } = window._coreProvider;
|
|
||||||
// this call enforces signature check to detect license update
|
|
||||||
// and causes license re-fetch
|
|
||||||
await setup.core.http.get('/');
|
|
||||||
await testUtils.delay(1000);
|
|
||||||
|
|
||||||
const licensing: LicensingPluginSetup = setup.plugins.licensing;
|
|
||||||
licensing.license$.subscribe((license) => cb(license.type));
|
|
||||||
})
|
|
||||||
).to.be('basic');
|
|
||||||
|
|
||||||
|
// switch to trial (can do it only once)
|
||||||
await scenario.startTrial();
|
await scenario.startTrial();
|
||||||
await scenario.waitForPluginToDetectLicenseUpdate();
|
license = await fetchLatestLicense();
|
||||||
|
expect(license.type).to.be('trial');
|
||||||
|
|
||||||
expect(
|
// ensure consecutive fetch still yields 'trial'
|
||||||
await browser.executeAsync(async (cb) => {
|
license = await fetchLatestLicense();
|
||||||
const { setup, testUtils } = window._coreProvider;
|
expect(license.type).to.be('trial');
|
||||||
// this call enforces signature check to detect license update
|
|
||||||
// and causes license re-fetch
|
|
||||||
await setup.core.http.get('/');
|
|
||||||
await testUtils.delay(1000);
|
|
||||||
|
|
||||||
const licensing: LicensingPluginSetup = setup.plugins.licensing;
|
|
||||||
licensing.license$.subscribe((license) => cb(license.type));
|
|
||||||
})
|
|
||||||
).to.be('trial');
|
|
||||||
|
|
||||||
|
// switch back to basic
|
||||||
await scenario.startBasic();
|
await scenario.startBasic();
|
||||||
await scenario.waitForPluginToDetectLicenseUpdate();
|
license = await fetchLatestLicense();
|
||||||
|
expect(license.type).to.be('basic');
|
||||||
expect(
|
|
||||||
await browser.executeAsync(async (cb) => {
|
|
||||||
const { setup, testUtils } = window._coreProvider;
|
|
||||||
// this call enforces signature check to detect license update
|
|
||||||
// and causes license re-fetch
|
|
||||||
await setup.core.http.get('/');
|
|
||||||
await testUtils.delay(1000);
|
|
||||||
|
|
||||||
const licensing: LicensingPluginSetup = setup.plugins.licensing;
|
|
||||||
licensing.license$.subscribe((license) => cb(license.type));
|
|
||||||
})
|
|
||||||
).to.be('basic');
|
|
||||||
|
|
||||||
// banner shown only when license expired not just deleted
|
// banner shown only when license expired not just deleted
|
||||||
await testSubjects.missingOrFail('licenseExpiredBanner');
|
await testSubjects.missingOrFail('licenseExpiredBanner');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue