Skip to content

Commit 6e6c8b3

Browse files
authored
test: fix race between sample and system tests (#98)
Both were writing to the default `winston_log` log in Stackdriver and system tests would fail when unexpected logs would show up rather than the expected logs. Fixes #78
1 parent 055d32d commit 6e6c8b3

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

handwritten/nodejs-logging-winston/system-test/logging-winston.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ import * as types from '../src/types/core';
2121

2222
const logging = require('@google-cloud/logging')();
2323
const LoggingWinston = require('../src/index').LoggingWinston;
24+
const LOG_NAME = 'winston_log_system_tests';
2425

2526
describe('LoggingWinston', () => {
2627
const WRITE_CONSISTENCY_DELAY_MS = 90000;
2728

2829
const logger = new winston.Logger({
29-
transports: [new LoggingWinston()],
30+
transports: [new LoggingWinston({logName: LOG_NAME})],
3031
});
3132

3233
describe('log', () => {
@@ -96,21 +97,20 @@ describe('LoggingWinston', () => {
9697
(logger as any)[test.level].apply(logger, test.args);
9798
});
9899
setTimeout(() => {
99-
logging.log('winston_log')
100-
.getEntries(
101-
{
102-
pageSize: testData.length,
103-
},
104-
(err: Error, entries: types.StackdriverEntry[]) => {
105-
assert.ifError(err);
106-
assert.strictEqual(entries.length, testData.length);
107-
entries.reverse().forEach((entry, index) => {
108-
const test = testData[index];
109-
test.verify(entry);
110-
});
100+
logging.log(LOG_NAME).getEntries(
101+
{
102+
pageSize: testData.length,
103+
},
104+
(err: Error, entries: types.StackdriverEntry[]) => {
105+
assert.ifError(err);
106+
assert.strictEqual(entries.length, testData.length);
107+
entries.reverse().forEach((entry, index) => {
108+
const test = testData[index];
109+
test.verify(entry);
110+
});
111111

112-
done();
113-
});
112+
done();
113+
});
114114
}, WRITE_CONSISTENCY_DELAY_MS);
115115
});
116116
});

0 commit comments

Comments
 (0)