-
Notifications
You must be signed in to change notification settings - Fork 935
feature: allow sync flag to be passed to ThreadStream for synchronous… #2063
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
Merged
+74
−5
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
89094c9
feature: allow sync flag to be passed to ThreadStream for synchronous…
karankraina 341c330
tests: add unit tests for sync true to ThreadStream
karankraina aeeea51
tests: fix unit test
karankraina f977b11
karankraina/fix-tests
karankraina b4bc448
tests: fix unit test
karankraina 2684d4a
karankraina/fix-tests
karankraina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| 'use strict' | ||
|
|
||
| const pino = require('../..') | ||
| const { join } = require('node:path') | ||
| const { readFileSync } = require('node:fs') | ||
| const { test } = require('tap') | ||
| const { file } = require('../helper') | ||
|
|
||
| test('thread-stream sync true should log synchronously', async (t) => { | ||
| const outputPath = file() | ||
|
|
||
| function getOutputLogLines () { | ||
| return (readFileSync(outputPath)).toString().trim().split('\n').map(JSON.parse) | ||
| } | ||
|
|
||
| const transport = pino.transport({ | ||
| target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'), | ||
| options: { destination: outputPath, flush: true }, | ||
| sync: true | ||
| }) | ||
| const instance = pino(transport) | ||
|
|
||
| var value = { message: 'sync' } | ||
| instance.info(value) | ||
| instance.info(value) | ||
| instance.info(value) | ||
| instance.info(value) | ||
| instance.info(value) | ||
| instance.info(value) | ||
| let interrupt = false | ||
| let flushData | ||
| let loopCounter = 0 | ||
|
|
||
| // Start a synchronous loop | ||
| while (!interrupt && loopCounter < (process.env.MAX_TEST_LOOP_ITERATION || 20000)) { | ||
| try { | ||
| loopCounter++ | ||
| const data = getOutputLogLines() | ||
| flushData = data | ||
| if (data) { | ||
| interrupt = true | ||
| break | ||
| } | ||
| } catch (error) { | ||
| // File may not exist yet | ||
| // Wait till MAX_TEST_LOOP_ITERATION iterations | ||
| } | ||
| } | ||
|
|
||
| if (!interrupt) { | ||
| throw new Error('Sync loop did not get interrupt') | ||
| } | ||
|
|
||
| t.equal(flushData.length, 6) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.