Skip to content

test(contrib/drivers/gaussdb): add transaction, where, hook, ctx test coverage - #4685

Merged
gqcn merged 2 commits into
gogf:masterfrom
lingcoder:test/gaussdb-transaction-where-hook-ctx
Feb 26, 2026
Merged

test(contrib/drivers/gaussdb): add transaction, where, hook, ctx test coverage#4685
gqcn merged 2 commits into
gogf:masterfrom
lingcoder:test/gaussdb-transaction-where-hook-ctx

Conversation

@lingcoder

@lingcoder lingcoder commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Port 4 test files from PgSQL driver to GaussDB driver to align test coverage
  • Add gaussdb_z_unit_transaction_test.go (40 tests): nested transactions, savepoints, rollback, panic recovery, context propagation
  • Add gaussdb_z_unit_model_where_test.go (35 tests): comprehensive Where clause combinations (map, slice, struct, pointer, operators, nil, empty)
  • Add gaussdb_z_unit_feature_hook_test.go (6 tests): model hook callbacks (Select/Insert/Update/Delete)
  • Add gaussdb_z_unit_feature_ctx_test.go (5 tests): context propagation, timeout, logging with context
  • Remove old Test_Model_Where (2 sub-tests) from gaussdb_z_unit_model_test.go, replaced by comprehensive version in dedicated where test file (35 tests)
  • 86 new test functions, ~3,224 net new lines

Test plan

  • go build ./... passes
  • gofmt and gci applied
  • No remaining pgsql references in new files
  • Run go test -v -run "Test_TX_" -count=1 against GaussDB instance
  • Run go test -v -run "Test_Model_Where" -count=1 against GaussDB instance
  • Run go test -v -run "Test_Model_Hook" -count=1 against GaussDB instance
  • Run go test -v -run "Test_Ctx" -count=1 against GaussDB instance

ref #4689

… coverage

Port 4 test files from PgSQL driver to GaussDB driver to align test coverage:
- gaussdb_z_unit_transaction_test.go (40 tests)
- gaussdb_z_unit_model_where_test.go (35 tests)
- gaussdb_z_unit_feature_hook_test.go (6 tests)
- gaussdb_z_unit_feature_ctx_test.go (5 tests)

Remove old Test_Model_Where from gaussdb_z_unit_model_test.go,
replaced by comprehensive version in dedicated where test file.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 expands the GaussDB driver test suite by porting and extending unit/feature tests (transactions, WHERE clause handling, hooks, and context propagation) to better align coverage with other SQL drivers.

Changes:

  • Added extensive transaction tests covering nested transactions, savepoints, propagation modes, panic recovery, and isolation levels.
  • Added a dedicated and comprehensive Model.Where/WherePri/... test file, replacing a smaller Test_Model_Where in the existing model test file.
  • Added feature tests for model hooks and context propagation behaviors.

Reviewed changes

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

Show a summary per file
File Description
contrib/drivers/gaussdb/gaussdb_z_unit_transaction_test.go Adds broad transaction behavior coverage (nested TX, savepoints, propagation, isolation).
contrib/drivers/gaussdb/gaussdb_z_unit_model_where_test.go Adds comprehensive WHERE/WHEREPRI coverage across many input forms and operators.
contrib/drivers/gaussdb/gaussdb_z_unit_model_test.go Removes the older minimal Test_Model_Where now covered by the new dedicated file.
contrib/drivers/gaussdb/gaussdb_z_unit_feature_hook_test.go Adds hook handler tests for Select/Insert/Update/Delete behaviors.
contrib/drivers/gaussdb/gaussdb_z_unit_feature_ctx_test.go Adds tests around context propagation, logging keys, transactions, and timeouts.

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

Comment thread contrib/drivers/gaussdb/gaussdb_z_unit_feature_hook_test.go
Comment thread contrib/drivers/gaussdb/gaussdb_z_unit_feature_hook_test.go
Comment thread contrib/drivers/gaussdb/gaussdb_z_unit_transaction_test.go
Comment thread contrib/drivers/gaussdb/gaussdb_z_unit_transaction_test.go
Comment thread contrib/drivers/gaussdb/gaussdb_z_unit_transaction_test.go
Comment thread contrib/drivers/gaussdb/gaussdb_z_unit_transaction_test.go
@lingcoder

lingcoder commented Feb 12, 2026

Copy link
Copy Markdown
Contributor Author

@gqcn 感谢review,这里解释一下几个设计选择:

关于事务测试忽略Insert错误:
测试重点在PropagationRequiresNew的事务隔离性 - 验证tx2的独立事务不受外层tx.Rollback()影响。MySQL驱动在同样场景下也是忽略Insert返回值直接验证事务行为,为了保持Layer 2测试跨驱动的可移植性,GaussDB这里沿用了相同模式。

关于Hook测试用db.Model:
Hook测试要验证的是Hook替换机制本身,用db.Model可以避免Hook嵌套干扰测试结果。Context传递的测试在Test_Model_Ctx里专门覆盖,不用在Hook测试里重复。而且Hook函数通过in参数已经拿到完整上下文了,这个设计跟MySQL的Hook测试保持一致。

关于Ctx测试忽略返回值:
这个测试验证的是Context传播链路(traceId能不能正确传到日志里),不关心查询本身的结果。断言只检查日志内容,所以查询成不成功不影响验证逻辑。MySQL的Ctx测试也是同样设计。

这些模式都是为了跟MySQL基线对齐,方便后续横向比对各驱动的测试覆盖率。👍

@gqcn
gqcn merged commit 841003e into gogf:master Feb 26, 2026
18 checks passed
@lingcoder
lingcoder deleted the test/gaussdb-transaction-where-hook-ctx branch February 28, 2026 00:31
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.

3 participants