Skip to content

Commit 018dbee

Browse files
dmlemeshkoCAWilson94
authored andcommitted
[scout] pre-create ES .security-* indexes before parallel tests are run (elastic#234269)
## Summary Adding `preCreateSecurityIndexes` Playwright fixture to run automatically as a part of `globalSetup` hook for parallel tests execution. This fixture is a workaround to pre-create ES `.security-*` indexes before actual tests run: today we periodically see ES responding with 401 when authentication is run concurrently while those indexes do not exist. Since Kibana doesn't retry this error, tests execution fails due to failed login.
1 parent 161a993 commit 018dbee

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/platform/packages/shared/kbn-scout/src/playwright/test/ui/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
*/
99

1010
import { scoutFixtures, lighthouseFixtures } from './single_thread_fixtures';
11-
import { scoutParallelFixtures, globalSetup } from './parallel_run_fixtures';
11+
import { scoutParallelFixtures, globalSetupFixtures } from './parallel_run_fixtures';
1212

1313
// Scout UI test fixtures: single-threaded
1414
export const test = scoutFixtures;
1515
// Scout UI test fixtures: single-threaded with Lighthouse
1616
export const lighthouseTest = lighthouseFixtures;
1717
// Scout core 'space aware' fixtures: parallel execution
1818
export const spaceTest = scoutParallelFixtures;
19-
// Scout global setup hook for parallel execution
20-
export const globalSetupHook = globalSetup;
19+
// Scout global 'setup' hook for parallel execution
20+
export const globalSetupHook = globalSetupFixtures;
2121

2222
export type { ScoutTestFixtures, ScoutWorkerFixtures } from './single_thread_fixtures';
2323
export type {

src/platform/packages/shared/kbn-scout/src/playwright/test/ui/parallel_run_fixtures.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from '../../fixtures/scope/worker';
1818
import type {
1919
ApiServicesFixture,
20+
CoreWorkerFixtures,
2021
EsClient,
2122
KbnClient,
2223
KibanaUrl,
@@ -60,9 +61,34 @@ export interface ScoutParallelWorkerFixtures {
6061
apiServices: ApiServicesFixture;
6162
}
6263

63-
export const globalSetup = mergeTests(
64+
/**
65+
* Pre-creates Elasticsearch Security indexes (.security-tokens, .security-profile)
66+
* during global setup to prevent race conditions when parallel tests perform their first SAML authentication.
67+
*/
68+
const preCreateSecurityIndexesFixture = coreWorkerFixtures.extend<
69+
{},
70+
{ samlAuth: CoreWorkerFixtures['samlAuth']; preCreateSecurityIndexes: void }
71+
>({
72+
preCreateSecurityIndexes: [
73+
async (
74+
{
75+
samlAuth,
76+
log,
77+
}: { samlAuth: CoreWorkerFixtures['samlAuth']; log: CoreWorkerFixtures['log'] },
78+
use: (arg: void) => Promise<void>
79+
) => {
80+
log.debug('Running SAML authentication to pre-create Elasticsearch .security indexes');
81+
await samlAuth.session.getInteractiveUserSessionCookieWithRoleScope('admin');
82+
await use();
83+
},
84+
{ scope: 'worker', auto: true },
85+
],
86+
});
87+
88+
export const globalSetupFixtures = mergeTests(
6489
coreWorkerFixtures,
6590
esArchiverFixture,
6691
synthtraceFixture,
67-
apiServicesFixture
92+
apiServicesFixture,
93+
preCreateSecurityIndexesFixture
6894
);

0 commit comments

Comments
 (0)