Skip to content

Split public and internal drainStream and cover with tests#578

Merged
peter-leonov-ch merged 14 commits intomainfrom
always_drain_stream_2
Mar 2, 2026
Merged

Split public and internal drainStream and cover with tests#578
peter-leonov-ch merged 14 commits intomainfrom
always_drain_stream_2

Conversation

@peter-leonov-ch
Copy link
Copy Markdown
Collaborator

@peter-leonov-ch peter-leonov-ch commented Feb 25, 2026

Summary

This is a more conservative version of:

Here we keep the iterator approach for future.

Also, splitting the public API drainStream() from the new drainStreamInternal() internal one.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 79.06977% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/client-node/src/connection/stream.ts 77.50% 6 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@peter-leonov-ch peter-leonov-ch changed the title Always drain stream, attempt 2 Cover drainStream with tests Feb 25, 2026
@peter-leonov-ch peter-leonov-ch marked this pull request as ready for review February 25, 2026 19:38
Copilot AI review requested due to automatic review settings February 25, 2026 19:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive test coverage for the drainStream functionality and splits it into two separate functions: a public drainStream API and an internal drainStreamInternal function with enhanced logging. The changes address race conditions where streams may already be in a terminal state (errored, ended, or closed) before draining begins.

Changes:

  • Split drainStream into public API and drainStreamInternal with logging
  • Added early return checks for streams that are already errored, ended, or closed to prevent race conditions
  • Added comprehensive unit tests for both functions covering all major stream states
  • Updated internal code to use drainStreamInternal instead of drainStream

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/client-node/src/connection/stream.ts Introduced new public drainStream function and refactored existing one to drainStreamInternal with added logging and early state checks
packages/client-node/src/connection/node_base_connection.ts Updated all internal calls to use drainStreamInternal instead of drainStream; minor code organization improvements
packages/client-node/tests/unit/node_stream.test.ts Added comprehensive unit tests for the public drainStream API
packages/client-node/tests/unit/node_stream_internal.test.ts Added comprehensive unit tests for the internal drainStreamInternal function
packages/client-node/tests/integration/node_exec.test.ts Updated integration tests to use drainStreamInternal for internal test utilities

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@peter-leonov-ch peter-leonov-ch changed the title Cover drainStream with tests Split public and internal drainStream and cover with tests Feb 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* will result in closing the underlying socket, and negate the KeepAlive feature benefits.
* See https://github.com/ClickHouse/clickhouse-js/pull/203 */
export async function drainStream(
export async function drainStream(stream: Stream.Readable): Promise<void> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the rationale to make the method public?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slvrtrn can you help us out here? I see sleep is also public in the common module?

Maybe we cut the public ones asap until we know what's required, this should help reduce the API surface to support.

@peter-leonov-ch
Copy link
Copy Markdown
Collaborator Author

@copilot review risks this PR can introduce.

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 26, 2026

@peter-leonov-ch I've opened a new pull request, #582, to work on those changes. Once the pull request is ready, I'll request review from you.

mshustov
mshustov previously approved these changes Feb 27, 2026
@peter-leonov-ch peter-leonov-ch force-pushed the always_drain_stream_2 branch from 6e90efb to b976d08 Compare March 2, 2026 12:53
@peter-leonov-ch peter-leonov-ch merged commit d0f67b7 into main Mar 2, 2026
91 of 93 checks passed
@peter-leonov-ch peter-leonov-ch deleted the always_drain_stream_2 branch March 2, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants