Skip to content

test: add misbehaving mock ClickHouse harness (#194)#226

Draft
MukundaKatta wants to merge 1 commit intoClickHouse:mainfrom
MukundaKatta:test/misbehaving-mock-clickhouse
Draft

test: add misbehaving mock ClickHouse harness (#194)#226
MukundaKatta wants to merge 1 commit intoClickHouse:mainfrom
MukundaKatta:test/misbehaving-mock-clickhouse

Conversation

@MukundaKatta
Copy link
Copy Markdown

Summary

Closes #194. Adds an in-process Python ThreadingHTTPServer mock that returns malformed, partial, slow, or dropped HTTP responses, plus a 17-case pytest suite that locks down the wire-level contract of each misbehavior.

Mock approach (test/mock/mock_clickhouse.py)

Dispatches on a -- BEHAVIOR=<name> marker embedded in the request body or ?behavior= query string. Each behavior emits malformed bytes directly to the socket — some bypass send_response / shutdown mid-body — so the real libcurl + parser.c paths see the kinds of responses real ClickHouse never produces.

Behaviors covered

5xx errors with and without X-ClickHouse-Exception-Code, unterminated array literals (PR #188 regression class), truncated chunked transfer, slow headers / timeout exercise, truncated JSON, mid-body drops, trailing binary garbage, unterminated quoted strings, backslash at EOF, wrong Content-Length, request log.

Files changed

All new, all under test/mock/:

  • mock_clickhouse.py — server
  • test_mock_clickhouse.py — pytest (17 cases)
  • conftest.py — sys.path
  • mock_misbehaving.sql — opt-in SQL driver, deliberately outside test/sql/ so make installcheck is unaffected
  • README.md — documentation

761 lines total. No source code changes.

Test plan

  • ruff format clean, ruff check clean, codespell clean
  • pytest -v 17/17 passed in 8.26s
  • Verifies the mock's wire-level contract end-to-end without needing PostgreSQL or ClickHouse running

Closes ClickHouse#194 (issue, not PR). Adds a small in-process HTTP server under
test/mock/ that intentionally returns malformed, partial, slow, or
dropped responses so the parser and HTTP transport can be exercised
against the kinds of inputs the real ClickHouse never produces.

Behaviors covered: 5xx errors, unterminated array literals (the bug
class fixed in ClickHouse#188), truncated chunked transfers, slow headers,
truncated JSON, mid-body socket drops, trailing binary garbage,
unterminated quoted strings, backslash at EOF, and Content-Length
that overstates the body.

Includes a 17-case pytest suite (test/mock/test_mock_clickhouse.py)
that locks the wire-level shape of each behavior and is independent
of PostgreSQL/ClickHouse, plus an opt-in SQL driver script
(test/mock/mock_misbehaving.sql) for running the same misbehaviors
through clickhouse_raw_query() once the mock is up. The SQL file
lives outside test/sql/ on purpose so it does not run in
make installcheck (which would fail without the mock running).
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@MukundaKatta
Copy link
Copy Markdown
Author

@CLAassistant check

@theory theory added the quality Quality controls, testing, test coverage label May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quality Quality controls, testing, test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test Against misbehaving Mock ClickHouse

3 participants