-
Notifications
You must be signed in to change notification settings - Fork 79
fix(logging): fix log flushing on exit MONGOSH-2883 #2547
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
base: main
Are you sure you want to change the base?
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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2142,12 +2142,7 @@ describe('e2e', function () { | |||||||||||||||||||||
await shell.executeLine("log.info('This is a custom entry')"); | ||||||||||||||||||||||
expect(shell.assertNoErrors()); | ||||||||||||||||||||||
await eventually(async () => { | ||||||||||||||||||||||
const log = await readLogFile< | ||||||||||||||||||||||
MongoLogEntryFromFile & { | ||||||||||||||||||||||
c: string; | ||||||||||||||||||||||
ctx: string; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
>(); | ||||||||||||||||||||||
const log = await readLogFile<MongoLogEntryFromFile>(); | ||||||||||||||||||||||
const customLogEntry = log.filter((logEntry) => | ||||||||||||||||||||||
logEntry.msg.includes('This is a custom entry') | ||||||||||||||||||||||
); | ||||||||||||||||||||||
|
@@ -2182,6 +2177,46 @@ describe('e2e', function () { | |||||||||||||||||||||
).to.have.lengthOf(1); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it('flushes log file (normal exit)', async function () { | ||||||||||||||||||||||
const shell = this.startTestShell({ | ||||||||||||||||||||||
args: [ | ||||||||||||||||||||||
'--nodb', | ||||||||||||||||||||||
'--eval', | ||||||||||||||||||||||
'for(let i=0; i < 10; i++) log.info("logging", {i}); log.getPath();', | ||||||||||||||||||||||
], | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
expect(await shell.waitForAnyExit()).to.equal(0); | ||||||||||||||||||||||
const log = await readReplLogFile(shell.output.trim()); | ||||||||||||||||||||||
for (let i = 0; i < 10; i++) { | ||||||||||||||||||||||
expect( | ||||||||||||||||||||||
log.some( | ||||||||||||||||||||||
(entry) => entry.msg === 'logging' && entry.attr?.i === i | ||||||||||||||||||||||
) | ||||||||||||||||||||||
).to.be.true; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
it('flushes log file (exception thrown)', async function () { | ||||||||||||||||||||||
const shell = this.startTestShell({ | ||||||||||||||||||||||
args: [ | ||||||||||||||||||||||
'--nodb', | ||||||||||||||||||||||
'--eval', | ||||||||||||||||||||||
'for(let i=0; i < 10; i++) log.info("logging", {i}); print(log.getPath()); throw new Error("uh oh")', | ||||||||||||||||||||||
], | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
expect(await shell.waitForAnyExit()).to.equal(1); | ||||||||||||||||||||||
const log = await readReplLogFile( | ||||||||||||||||||||||
shell.output.replace(/Error: uh oh/g, '').trim() | ||||||||||||||||||||||
); | ||||||||||||||||||||||
Comment on lines
+2209
to
+2211
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. The error message filtering using regex replacement is fragile and could inadvertently remove legitimate log content. Consider a more robust approach to extract the log path from shell output.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. I mean, I had similar thoughts here as well, although I was ultimately feeling like this is just fine for a test |
||||||||||||||||||||||
for (let i = 0; i < 10; i++) { | ||||||||||||||||||||||
expect( | ||||||||||||||||||||||
log.some( | ||||||||||||||||||||||
(entry) => entry.msg === 'logging' && entry.attr?.i === i | ||||||||||||||||||||||
) | ||||||||||||||||||||||
).to.be.true; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
describe('history file', function () { | ||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.