Skip to content

Commit

Permalink
chore(Tests): Split form-related tests
Browse files Browse the repository at this point in the history
Currently, we have 3 that take a long time due to their nature. Each of these tests takes one catalog category and renders the configuration form for each of them.

While this works, the penalty is that we block jest worker nodes (threads) so the tests are pinned to a single worker without any chance of splitting the work, making the test slow.

This commit splits them into smaller sections, so the tests are better
distributed among all available worker nodes (threads).

Comparison:

* No split
```
Time:        109.227 s
Time:        143.646 s
```

* Split
```
Time:        23.485 s
Time:        24.143 s
```
  • Loading branch information
lordrip committed Sep 25, 2024
1 parent 79f06af commit 19d3095
Show file tree
Hide file tree
Showing 18 changed files with 176 additions and 141 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 0, end: 50 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 50, end: 100 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 100, end: 150 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 150, end: 200 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 200, end: 250 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 250, end: 300 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Component, range: { start: 300, end: undefined } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Pattern, range: { start: 0, end: undefined } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 0, end: 50 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 50, end: 100 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 100, end: 150 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 150, end: 200 } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { CatalogKind } from '../../../../../models';
import { FormTest } from './FormTest';

const target = { kind: CatalogKind.Kamelet, range: { start: 200, end: undefined } };

describe(`Form: ${target.kind} - [${target.range.start} - ${target.range.end}]`, () => {
FormTest(target);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { AutoField, AutoFields, AutoForm } from '@kaoto-next/uniforms-patternfly';
import catalogLibrary from '@kaoto/camel-catalog/index.json';
import { CatalogLibrary } from '@kaoto/camel-catalog/types';
import { render } from '@testing-library/react';
import { CamelCatalogService, CatalogKind, KaotoSchemaDefinition } from '../../../../../models';
import { getFirstCatalogMap } from '../../../../../stubs/test-load-catalog';
import { SchemaService } from '../../../../Form';
import { CustomAutoFieldDetector } from '../../../../Form/CustomAutoField';
import { getSchemasSlice } from './get-schemas-slices';

export const FormTest = (target: { kind: CatalogKind; range: { start: number; end: number | undefined } }) => {
let schemas: [string, KaotoSchemaDefinition['schema']][] = [];

beforeAll(async () => {
const catalogsMap = await getFirstCatalogMap(catalogLibrary as CatalogLibrary);

CamelCatalogService.setCatalogKey(CatalogKind.Component, catalogsMap.componentCatalogMap);
CamelCatalogService.setCatalogKey(CatalogKind.Pattern, catalogsMap.patternCatalogMap);
CamelCatalogService.setCatalogKey(CatalogKind.Kamelet, catalogsMap.kameletsCatalogMap);

schemas = getSchemasSlice(CamelCatalogService.getCatalogByKey(target.kind), target.range);
jest.spyOn(console, 'error').mockImplementation(() => {});
});

afterAll(() => {
jest.clearAllMocks();
});

it('should have schemas', () => {
expect(schemas).not.toHaveLength(0);
});

it('should render the form without an error', () => {
schemas.forEach(([name, schema]) => {
try {
const schemaService = new SchemaService();
const schemaBridge = schemaService.getSchemaBridge(schema);
render(
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
<AutoForm schema={schemaBridge!} model={{}} onChangeModel={() => {}}>
<AutoFields omitFields={SchemaService.OMIT_FORM_FIELDS} />
</AutoForm>
</AutoField.componentDetectorContext.Provider>,
);
} catch (e) {
console.error(e);
throw new Error(`Error rendering ${name} ${target.kind}`);
}
});
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
ICamelComponentDefinition,
ICamelProcessorDefinition,
IKameletDefinition,
KaotoSchemaDefinition,
} from '../../../../../models';

export const getSchemasSlice = (
catalogMap:
| Record<string, ICamelComponentDefinition>
| Record<string, ICamelProcessorDefinition>
| Record<string, IKameletDefinition>
| undefined,
range: { start: number; end: number | undefined },
): [string, KaotoSchemaDefinition['schema']][] => {
if (!catalogMap) return [];

return Object.entries(catalogMap)
.slice(range.start, range.end)
.map(([name, { propertiesSchema }]) => [name, propertiesSchema]);
};

0 comments on commit 19d3095

Please sign in to comment.