Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions system-test/test-middleware-koa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {Entry, Logging} from '@google-cloud/logging';
const logging = new Logging();

const WRITE_CONSISTENCY_DELAY_MS = 20 * 1000;
const TEST_TIMEOUT = WRITE_CONSISTENCY_DELAY_MS + 10 * 1000;
const TEST_TIMEOUT = 10 * 1000;
const LOG_NAME = `winston-system-test-${uuid.v4()}`;

function delay(ms: number) {
Expand All @@ -21,7 +21,7 @@ function delay(ms: number) {
describe('koa middleware', () => {
describe('global logger', () => {
it('should properly write log entries', async function () {
this.timeout(TEST_TIMEOUT);
this.timeout(TEST_TIMEOUT + WRITE_CONSISTENCY_DELAY_MS);
const logger = winston.createLogger();
await klw.makeMiddleware(logger, {
logName: LOG_NAME,
Expand All @@ -42,7 +42,10 @@ describe('koa middleware', () => {

describe('request logging middleware', () => {
it('should write request correlated log entries', async function () {
this.timeout(TEST_TIMEOUT);
const N_LOG_WRITE_CALLS = 2;
this.timeout(
TEST_TIMEOUT + N_LOG_WRITE_CALLS * WRITE_CONSISTENCY_DELAY_MS
);
const logger = winston.createLogger();
const mw = await klw.makeMiddleware(logger, {
logName: LOG_NAME,
Expand Down Expand Up @@ -93,12 +96,11 @@ describe('koa middleware', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await mw(fakeContext as any, next);

await delay(WRITE_CONSISTENCY_DELAY_MS);

const requestLog = logging.log(`${LOG_NAME}${REQUEST_LOG_SUFFIX}`);
const requestLogEntries = (
await requestLog.getEntries({
pageSize: 1,
})
)[0];
const [requestLogEntries, reqLogReq, reqLogRes] =
await requestLog.getEntries({pageSize: 1});
assert.strictEqual(requestLogEntries.length, 1);
const [requestLogEntry] = requestLogEntries;
assert.strictEqual(
Expand Down