refactor tests

This commit is contained in:
restrry 2021-10-12 16:53:32 +02:00
parent c3a167eb40
commit 464b3e2daf
4 changed files with 12 additions and 6 deletions

View file

@ -42,6 +42,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
`--elasticsearch.hosts=${servers.elasticsearch.protocol}://${servers.elasticsearch.hostname}:${servers.elasticsearch.port}`,
`--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`,
'--server.requestId.allowFromAnyIp=true',
'--execution_context.enabled=true',
'--logging.appenders.file.type=file',
`--logging.appenders.file.fileName=${logFilePath}`,

View file

@ -98,8 +98,7 @@ export class FixturePlugin implements Plugin<void, void, FixtureSetupDeps, Fixtu
transaction?.end();
subscription.unsubscribe();
});
// eslint-disable-next-line no-console
console.log('>>> in handler', apmAgent.isStarted(), apmAgent.currentTraceIds);
await ctx.core.elasticsearch.client.asInternalUser.ping();
return res.ok({

View file

@ -40,7 +40,7 @@ export async function assertLogContains({
retry: RetryService;
}): Promise<void> {
// logs are written to disk asynchronously. I sacrificed performance to reduce flakiness.
await retry.waitForWithTimeout(description, 60_000, async () => {
await retry.waitFor(description, async () => {
const logsStr = await Fs.readFile(logFilePath, 'utf-8');
const normalizedRecords = logsStr
.split(endOfLine)

View file

@ -14,7 +14,10 @@ export default function ({ getService }: FtrProviderContext) {
describe('Log Correlation', () => {
it('Emits "trace.id" into the logs', async () => {
const response1 = await supertest.get('/emit_log_with_trace_id');
const response1 = await supertest
.get('/emit_log_with_trace_id')
.set('x-opaque-id', 'myheader1');
expect(response1.body.traceId).to.be.a('string');
const response2 = await supertest.get('/emit_log_with_trace_id');
@ -23,8 +26,11 @@ export default function ({ getService }: FtrProviderContext) {
expect(response2.body.traceId).not.to.be(response1.body.traceId);
await assertLogContains({
description: `traceId ${response1.body.traceId} included in the Kibana logs`,
predicate: (record) => record.trace?.id === response1.body.traceId,
description: 'traceId included in the Kibana logs',
predicate: (record) =>
// we don't check trace.id value since trace.id in the test plugin and Kibana are different on CI.
// because different 'elastic-apm-node' instaces are imported
Boolean(record.http?.request?.id?.includes('myheader1') && record.trace?.id),
retry,
});
});