Skip to content

Commit

Permalink
Merge branch 'main' into ai_err
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 2, 2023
2 parents 50a69f4 + 007c341 commit dfcd52a
Show file tree
Hide file tree
Showing 124 changed files with 3,260 additions and 1,164 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ packages/core/status/core-status-server-mocks @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-deprecations-getters @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-http-setup-browser @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-kbn-server @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-model-versions @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-so-type-serializer @elastic/kibana-core
packages/core/test-helpers/core-test-helpers-test-utils @elastic/kibana-core
packages/core/theme/core-theme-browser @elastic/kibana-core
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,8 @@
"jsts": "^1.6.2",
"kea": "^2.4.2",
"langchain": "^0.0.151",
"launchdarkly-js-client-sdk": "^2.22.1",
"launchdarkly-node-server-sdk": "^6.4.2",
"launchdarkly-js-client-sdk": "^3.1.4",
"launchdarkly-node-server-sdk": "^7.0.3",
"load-json-file": "^6.2.0",
"lodash": "^4.17.21",
"lru-cache": "^4.1.5",
Expand Down Expand Up @@ -1180,6 +1180,7 @@
"@kbn/core-saved-objects-server-mocks": "link:packages/core/saved-objects/core-saved-objects-server-mocks",
"@kbn/core-status-server-mocks": "link:packages/core/status/core-status-server-mocks",
"@kbn/core-test-helpers-kbn-server": "link:packages/core/test-helpers/core-test-helpers-kbn-server",
"@kbn/core-test-helpers-model-versions": "link:packages/core/test-helpers/core-test-helpers-model-versions",
"@kbn/core-theme-browser-mocks": "link:packages/core/theme/core-theme-browser-mocks",
"@kbn/core-ui-settings-browser-mocks": "link:packages/core/ui-settings/core-ui-settings-browser-mocks",
"@kbn/core-ui-settings-server-mocks": "link:packages/core/ui-settings/core-ui-settings-server-mocks",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# @kbn/core-test-helpers-model-versions

Package exposing utilities for model version integration testing.

This package exposes a `createModelVersionTestBed` utility which allow simulating
a testbed environment where we're in the cohabitation period between two versions, to test the interactions
between two model versions of a set of SO types.

### Limitations:

Because the test bed is only creating the parts of Core required to create the two SO
repositories, and because we're not loading all plugins (for proper isolation), the integration
test bed has some limitations:

- no extensions are enabled
- no security
- no encryption
- no spaces
- all SO types will be using the same SO index
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { createModelVersionTestBed } from './src/test_bed';

export type {
ModelVersionTestBed,
ModelVersionTestKit,
ModelVersionTestkitOptions,
SavedObjectTestkitDefinition,
} from './src/types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../..',
roots: ['<rootDir>/packages/core/test-helpers/core-test-helpers-model-versions'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "shared-common",
"id": "@kbn/core-test-helpers-model-versions",
"owner": "@elastic/kibana-core",
"devOnly": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/core-test-helpers-model-versions",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { createTestServers, type TestElasticsearchUtils } from '@kbn/core-test-helpers-kbn-server';

/**
* Start the traditional ES cluster and return the instance.
*/
export const startElasticsearch = async ({
basePath,
dataArchive,
timeout,
}: {
basePath?: string;
dataArchive?: string;
timeout?: number;
} = {}): Promise<TestElasticsearchUtils> => {
const { startES } = createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t + (timeout ?? 0)),
settings: {
es: {
license: 'basic',
basePath,
dataArchive,
},
},
});
return await startES();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { TestElasticsearchUtils } from '@kbn/core-test-helpers-kbn-server';
import { startElasticsearch } from './elasticsearch';
import { prepareModelVersionTestKit } from './test_kit';
import type { ModelVersionTestBed } from './types';

/**
* Create a {@link ModelVersionTestBed} that can be used for model version integration testing.
*
* @example
* ```ts
* describe('myIntegrationTest', () => {
* const testbed = createModelVersionTestBed();
* let testkit: ModelVersionTestKit;
*
* beforeAll(async () => {
* await testbed.startES();
* });
*
* afterAll(async () => {
* await testbed.stopES();
* });
*
* beforeEach(async () => {
* testkit = await testbed.prepareTestKit({
* savedObjectDefinitions: [{
* definition: mySoTypeDefinition,
* modelVersionBefore: 1,
* modelVersionAfter: 2,
* }]
* })
* });
*
* afterEach(async () => {
* if(testkit) {
* await testkit.tearsDown();
* }
* });
*
* it('can be used to test model version cohabitation', async () => {
* // last registered version is `1`
* const repositoryV1 = testkit.repositoryBefore;
* // last registered version is `2`
* const repositoryV2 = testkit.repositoryAfter;
*
* // do something with the two repositories, e.g
* await repositoryV1.create(someAttrs, { id });
* const v2docReadFromV1 = await repositoryV2.get('my-type', id);
* expect(v2docReadFromV1.attributes).toEqual(something);
* })
* })
* ```
*
* @public
*/
export const createModelVersionTestBed = (): ModelVersionTestBed => {
let elasticsearch: TestElasticsearchUtils | undefined;

const startES = async () => {
if (elasticsearch) {
throw new Error('Elasticsearch already started');
}
elasticsearch = await startElasticsearch();
};

const stopES = async () => {
if (!elasticsearch) {
throw new Error('Elasticsearch not started');
}
await elasticsearch.stop();
await delay(10);
elasticsearch = undefined;
};

return {
startES,
stopES,
prepareTestKit: prepareModelVersionTestKit,
};
};

const delay = (seconds: number) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));
Loading

0 comments on commit dfcd52a

Please sign in to comment.