-
Notifications
You must be signed in to change notification settings - Fork 33
fix: de-flake system tests #261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| import * as assert from 'assert'; | ||
| import delay from 'delay'; | ||
| import * as uuid from 'uuid'; | ||
|
|
||
| import {express as elb} from '../src/index'; | ||
|
|
||
|
|
@@ -26,23 +27,24 @@ const logging = new Logging(); | |
|
|
||
| const WRITE_CONSISTENCY_DELAY_MS = 20 * 1000; | ||
| const TEST_TIMEOUT = WRITE_CONSISTENCY_DELAY_MS + (10 * 1000); | ||
| const LOG_NAME = `bunyan-system-test-${uuid.v4()}`; | ||
|
|
||
| describe('express middleware', () => { | ||
| let logger: elb.MiddlewareReturnType['logger']; | ||
| let mw: elb.MiddlewareReturnType['mw']; | ||
|
|
||
| before(async () => { | ||
| ({logger, mw} = await elb.middleware({level: 'info'})); | ||
| ({logger, mw} = await elb.middleware({logName: LOG_NAME, level: 'info'})); | ||
| }); | ||
|
|
||
| describe('global logger', () => { | ||
| it('should properly write log entries', async () => { | ||
| const LOG_MESSAGE = 'test log message'; | ||
| const LOG_MESSAGE = `unique log message ${uuid.v4()}`; | ||
| logger.info(LOG_MESSAGE); | ||
|
|
||
| await delay(WRITE_CONSISTENCY_DELAY_MS); | ||
|
|
||
| const log = logging.log('bunyan_log'); | ||
| const log = logging.log(`${LOG_NAME}_applog`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this suffixed with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is suboptimal. The reason behind this is that for request bundling to work, the 'request log stream' (the log which has the http requests) has to be a different log name than the the 'application log' (where normal user logging should go). We chose to use a suffix for the applog, but it might have been better to use a suffix for the request log (since it is not user-generated). This will be fixed when a counterpart of this PR is ported over to this library. Note that you will still have two different log streams. |
||
| const entries = (await log.getEntries({pageSize: 1}))[0]; | ||
| assert.strictEqual(entries.length, 1); | ||
| assert.strictEqual(LOG_MESSAGE, entries[0].data.message); | ||
|
|
@@ -51,7 +53,7 @@ describe('express middleware', () => { | |
|
|
||
| describe('request logging middleware', () => { | ||
| it('should write request correlated log entries', (done) => { | ||
| const LOG_MESSAGE = 'test request log message'; | ||
| const LOG_MESSAGE = `correlated log message ${uuid.v4()}`; | ||
| const fakeRequest = {headers: {fake: 'header'}}; | ||
| const fakeResponse = {}; | ||
| const next = async () => { | ||
|
|
@@ -61,7 +63,7 @@ describe('express middleware', () => { | |
|
|
||
| await delay(WRITE_CONSISTENCY_DELAY_MS); | ||
|
|
||
| const log = logging.log('bunyan_log'); | ||
| const log = logging.log(`${LOG_NAME}_applog`); | ||
| const entries = (await log.getEntries({pageSize: 1}))[0]; | ||
| assert.strictEqual(entries.length, 1); | ||
| const entry = entries[0]; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being picky, but couldn't this all be boiled down to:
It looks like we have a method that only gets called once with a single string.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the expectation is that we can have have more tests in this file in the future. They could potentially want to use unique log names.
The pedigree of this code is that is copied from sister winston library, which indeed has multiple tests.
I can make the change if you insist, but I do not think it is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not insist :)