已开启
Add Diesel compatibility tests for openGauss #108
Rourou2285创建于 7 天前
Add Diesel compatibility tests for openGauss #108
已开启
Rourou2285创建于 7 天前
Rourou2285
Rourou2285
7 天前

新增 Diesel ORM 连接 openGauss B 兼容模式数据库的完整兼容性测试示例(Diesel 2.3.12),基于 openGauss master 与 dolphin(含 MySQL 大包多 payload 重组修复)验证。

测试覆盖

  • 连接与 mysql_native_password 认证
  • CRUD、批量操作、LAST_INSERT_ID
  • 手动/自动/嵌套事务、多语句
  • 基础类型、日期时间、JSON、BLOB、DECIMAL、LONGTEXT
  • 过滤/排序/分页/聚合/JOIN/子查询
  • COM_STMT_PREPARE、语句复用、参数绑定
  • Diesel CLI 与嵌入式迁移
  • r2d2 连接池、并发、错误映射
  • Diesel typed DSL(QueryableByName、associations、for_update、typed Json)

测试结果

openGauss 7.0.0 (master) + dolphin master,共 76 例,基于 fresh-schema 重复执行:

PASS: 75
FAIL: 0
EXPECTED_FAIL: 1

已知限制

唯一 EXPECTED_FAIL 为 T8.2 diesel print-schema

  • dolphin 对 VARCHAR 内省返回 PostgreSQL 原生类型名 character varying
  • diesel_cli(MySQL backend)不识别该类型名,报 Unsupported type: character varying 并中止;
  • 该限制在 RC3 与 master 均存在,非回归,属 Dolphin↔Diesel 长期类型名不兼容。

注:原为 EXPECTED_FAIL 的 >16MB 多 payload 大包(T13.1)在 openGauss master 已修复(!2538 / commit fcd035ce),现为 PASS。

相关 Issue

Issue #46:B 库 B 协议适配 Rust ORM 框架 Diesel

likedislike
合并受阻
Rourou2285Rourou2285
7 天前 创建了 pull request,commit 2ffdb192
opengauss_botopengauss_bot成员
7 天前 添加了label:sig/Infra
opengauss_bot
opengauss_bot成员
7 天前 评论:

Welcome To openGauss Community

Hey @Rourou2285 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: Infra ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @ailoooong, @gzbang, @libiao2024, @zhangxubo .

likedislike
opengauss_botopengauss_bot成员
7 天前 添加了label:stat/needs-squash
此处折叠了6条事件消息 查看更多
opengauss_botopengauss_bot成员
4 天前 添加了label:opengauss-cla/yes
liyangx成员
3 天前 评论:

/ai review

likedislike
atomgit-bot
atomgit-bot成员
3 天前 评论:

代码审查

审查结果

发现汇总(共 6 条)

优先级 数量 说明
P0 0
P1 0
P2 1 T13.1 断言未校验 17MB 大包回读长度
P3 5 死代码、Dockerfile 架构硬编码、curl|sh、版本未固定、幂等性

逐文件审查确认

  • DieselCompatibility2openGauss/.env.example — no issues(占位口令,非真实凭据)。
  • DieselCompatibility2openGauss/.gitignore — no issues(Cargo.lock 被忽略的可复现性问题已并入 Cargo.toml 条目)。
  • DieselCompatibility2openGauss/Cargo.toml — 1 条:diesel = "2" 未固定为测试声明的 2.3.12,且 Cargo.lock 被 gitignore、diesel_cli 未固定版本,兼容性测试结论可能随上游版本静默漂移(P3)。
  • DieselCompatibility2openGauss/diesel.toml — no issues(纯注释配置)。
  • DieselCompatibility2openGauss/docker/Dockerfile — 2 条:PATH 硬编码 x86_64 toolchain 目录(架构不可移植,P3);curl ... | sh 直接执行未校验脚本(供应链加固,P3)。
  • DieselCompatibility2openGauss/migrations/20240101000000_init/up.sql — no issues。
  • DieselCompatibility2openGauss/migrations/20240101000000_init/down.sql — no issues。
  • DieselCompatibility2openGauss/sql/init.sql — no issues(测试 schema 的授权与建表语句,无注入、无越权风险)。
  • DieselCompatibility2openGauss/src/cases/connectivity.rs — no issues(空 URL 时用例失败属环境配置行为,非代码缺陷)。
  • DieselCompatibility2openGauss/src/cases/convention.rs — 1 条:T7.2 建表/删表非幂等,遗留 t7_tmp 会导致假阴性(P3)。
  • DieselCompatibility2openGauss/src/cases/crud.rs — no issues(T2.4 的 unwrap_or(0) 在 T2.3 失败时自然级联失败,逻辑自洽)。
  • DieselCompatibility2openGauss/src/cases/migrations.rs — no issues(CLI 子进程 CWD/环境依赖属运行环境约定;用例间状态流转与级联失败语义正确)。
  • DieselCompatibility2openGauss/src/cases/mod.rs — no issues(声明的模块在工作区中均存在)。
  • DieselCompatibility2openGauss/src/cases/pool.rs — no issues(T12.1–T12.4 的池并发、跨连接可见性、错误映射断言逻辑正确;unwrap() 恐慌路径在池容量内不可达)。
  • DieselCompatibility2openGauss/src/cases/prepared.rs — no issues(T6.5 100KB TEXT 回读比较正确)。
  • DieselCompatibility2openGauss/src/cases/protocol.rs — 2 条:T13.1 无条件 r.record(true),未将 LENGTH(c_long) 回读纳入断言,数据截断/长度查询失败时仍误报 PASS(P2,本 PR 最值得关注的测试逻辑缺口);未使用的 lower 死代码(P3)。

总体风险评估

本 PR 全部为测试代码与配套配置,不涉及生产逻辑,无 P0/P1 级问题。整体风险较低,但存在一处中等优先级测试断言缺口:T13.1 声称验证 openGauss master 的 >16MB 多 payload 重组修复,却未对回读长度做断言,存在假阳性风险,建议修复后再作为该修复的回归证据。其余为低优先级的可复现性、幂等性与镜像加固建议,不影响当前 75 PASS / 1 EXPECTED_FAIL 的结论有效性。


关闭总结

各文件审查结论

文件 审查结论
DieselCompatibility2openGauss/src/cases/queries.rs 已逐条核对 T5.x/T9.x 的 SQL 语义与期望值(过滤、NULL、like/between/in、排序、分页、聚合、group_by+having、join、distinct、LEFT/RIGHT/CROSS/FULL JOIN、子查询、EXISTS、=ANY),数值与索引均正确;聚合 sum/avg 容忍度合理。no issues。
DieselCompatibility2openGauss/src/cases/transactions.rs 发现 1 个问题(P3):T3.5 && 短路链在任一步失败时跳过 ROLLBACKSET autocommit=1 恢复,会话 autocommit=0 状态泄漏到后续所有用例(T3.1/T3.2 存在同类短链问题)。T3.7 多语句、T11.x upsert/SAVEPOINT/嵌套事务逻辑本身核对无误。
DieselCompatibility2openGauss/src/cases/typed_dsl.rs 发现 2 个问题:P2——T14.6 let _ = 丢弃 for_update().load() 结果导致用例恒 PASS、无法检测 FOR UPDATE 兼容性(本 PR 最重要问题);P3——T14.1 的 v[3].1.is_none() 断言隐式依赖引擎 NULL 排序语义。其余(LEFT JOIN 行数、eq_any 子查询、AsChangeset、QueryableByName、belonging_to、typed Json)核对无误。
DieselCompatibility2openGauss/src/cases/types.rs 发现 1 个问题(P3):CREATE TABLE 结果被丢弃后无条件 cleanup(),DDL 不兼容时会 panic 中止整套用例。T4.x 类型 round-trip、T10.x 的 ENUM/BLOB/JSON/DECIMAL/大文本断言数值均核对无误。
DieselCompatibility2openGauss/src/common.rs TestResult 计数/合并、record/record_expected_fail 语义一致;cleanup/connect 的 panic 为注释明示的有意设计;无注入面(表名均为内部常量)。no issues。
DieselCompatibility2openGauss/src/main.rs 11 个 runner 的函数指针签名与本 diff 新增模块的 run 一致,退出码逻辑正确。no issues。
DieselCompatibility2openGauss/src/models.rs 各派生宏(Queryable/Insertable/Identifiable/Associations/AsChangeset)与 schema.rs 的列类型、字段名一一对应,无不一致。no issues。
DieselCompatibility2openGauss/src/schema.rs table!/joinable!/allow_tables_to_appear_in_same_query! 与使用处(inner_join、left_join、跨表子查询)一致。no issues。

发现统计

  • P0:0
  • P1:0
  • P2:1(T14.6 假通过用例,吞掉 for_update 查询错误)
  • P3:3(T3.5 短路链状态泄漏;T14.1 NULL 排序断言脆弱;CREATE 失败触发 cleanup panic 中止整套用例)

总体风险评估

本 PR 为新增的 Diesel↔openGauss B 库兼容性测试套件,8 个文件全部为新增代码,无既有逻辑被改动。SQL 期望值、类型映射、事务语义经逐条核对基本正确,无 P0/P1 级问题;存在 1 个会掩盖真实回归的假通过用例(T14.6)和 3 个测试健壮性/可移植性缺陷,均集中在测试断言与清理逻辑上,不影响被测功能本身,但会削弱该套件作为兼容性看门狗的检出能力与故障可诊断性,建议在合并前修复 P2 项。

(注:main.rs 引用的 connectivity/crud/prepared/convention/migrations/pool/protocol 等模块与 Cargo.toml、迁移脚本不在本 diff 范围内,且工作区受审查范围限制无法读取,未纳入核对。)

类型 数量
🔴 阻塞 0
🟡 建议 2

💬 仅评论

likedislike
Rourou2285Rourou2285
3 天前 update merge request[project id: 5089494, iid: 108, commit_id: 1425112e6566f54c842bf7a3a68656e67c9365a1] virtual merging success
Rourou2285Rourou2285
3 天前 推送  1 个提交:e90cbae5-[dolphin] Add Diesel introspection tests for MySQL type names (Issue #46)
Rourou2285Rourou2285
3 天前 update merge request[project id: 5089494, iid: 108, commit_id: 5ad8c7459996d0041f65cb33934323dd8e51fb76] virtual merging success
opengauss_botopengauss_bot成员
3 天前 删除了label:opengauss-cla/yes
opengauss_botopengauss_bot成员
3 天前 添加了label:opengauss-cla/yes
atomgit-bot
atomgit-bot成员3 天前进行代码检视2
DieselCompatibility2openGauss/src/cases/protocol.rs
已过期
@@ -0,0 +28,4 @@
28+ r.record(true, "T13.1", &format!(">16MB 大包成功(多 payload 重组支持):length={len:?}"));
29+ } else {
30+ let e = ins.as_ref().err().map(|x| x.to_string()).unwrap_or_default();
31+ let lower = e.to_ascii_lowercase();
atomgit-bot
atomgit-bot3 天前评论:

🔵 Low Priority

变更行:let lower = e.to_ascii_lowercase();(protocol.rs 31 行)。

受影响行为:该变量在整个 else 分支中从未被使用——错误描述只用 e.chars().take(80)lower 是遗留的无用计算(疑似当初打算按小写错误文本匹配"lost connection"之类关键词)。

失败模式:无功能影响,但属于死代码,并暗示用例可能遗漏了对错误文本的分类处理(例如区分"断连"与"其他错误"),容易被后续维护者误认为已处理。

建议:删除第 31 行 let lower = e.to_ascii_lowercase();;若本意是对错误文本做分类判断(如区分断连与普通错误),应补上实际使用它的分支逻辑。

likedislike
System
系统消息系统
3 天前 评论:

changed this line on a5fde4d3 view diff detail

atomgit-bot
atomgit-bot成员3 天前进行代码检视2
DieselCompatibility2openGauss/src/cases/typed_dsl.rs
已过期
@@ -0,0 +66,4 @@
66+ 
67+ // T14.6 for_update:事务内 SELECT ... FOR UPDATE
68+ let fu = conn.transaction::<(), diesel::result::Error, _>(|c| {
69+ let _ = users::table.filter(users::id.eq(u1)).for_update().load::<User>(c);
atomgit-bot
atomgit-bot3 天前评论:

🟡 Medium Priority

变更行:let _ = users::table.filter(users::id.eq(u1)).for_update().load::<User>(c);load::<User> 返回的 Result<Vec<User>, diesel::result::Error> 直接用 let _ = 丢弃。

受影响契约:T14.6 的断言 fu = conn.transaction(...).is_ok() 只反映事务机制本身是否成功,完全不反映 SELECT ... FOR UPDATE 是否被 dolphin/openGauss 正确执行。

失败模式:即使 FOR UPDATE 语法不被支持、load 返回 Err,闭包仍继续返回 Ok(()),事务正常提交,fu 恒为 true,T14.6 无条件 PASS。该用例与注释宣称的「for_update(事务内 SELECT FOR UPDATE)」验证目标不符,属于假通过用例——若将来 FOR UPDATE 出现回归,本套件将无法检出。本 PR 的全部价值在于验证这些兼容性点,这类吞错写法会静默丢失验证信号。

改动建议
69
- let _ = users::table.filter(users::id.eq(u1)).for_update().load::<User>(c);
69
+ users::table.filter(users::id.eq(u1)).for_update().load::<User>(c)?;
应用建议
likedislike
System
系统消息系统
3 天前 评论:

changed this line on a5fde4d3 view diff detail

Rourou2285Rourou2285
3 天前 update merge request[project id: 5089494, iid: 108, commit_id: 75c859f248d70e86ee262adba18584373e20f6ee] virtual merging success
此处折叠了6条事件消息 查看更多
Rourou2285Rourou2285
3 天前 update merge request[project id: 5089494, iid: 108, commit_id: 772c16da66eb6cdbe4b7d9f7f6cad65f9389bd3c] virtual merging success
Rourou2285
Rourou2285
3 天前 评论:

感谢 review,已处理中等优先级(P2)两点:

T13.1(protocol.rs):>16MB 大包现改为校验回读长度 LENGTH(c_long) == 17000000,不只是 INSERT 成功。插入成功但长度不符(截断/丢失)会记为 FAIL,避免假阳性。

T14.6(typed_dsl.rs:69)for_update().load()let _ = 丢弃改为 ? 传播错误——FOR UPDATE 失败会回滚事务、用例 FAIL(而非恒 PASS)。

protocol.rs 死代码:删除未使用的 let lower = ...

已提交 a5fde4d3 并推送到示例分支。P3 低优先项(Cargo.toml 版本固定、Dockerfile 架构/curl|sh、T7.2 幂等、T3.5 恢复等)已记录,可后续跟进或在本次一并收敛。

likedislike
opengauss_botopengauss_bot成员
3 天前 删除了label:opengauss-cla/yes
此处折叠了10条事件消息 查看更多
opengauss_botopengauss_bot成员
3 天前 添加了label:opengauss-cla/yes
opengauss_bot
opengauss_bot成员
3 天前 评论:

CLA Signature Pass

Rourou2285, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
Rourou2285
Rourou2285
3 天前 评论:

/ai review

likedislike
atomgit-bot
atomgit-bot成员
3 天前 评论:

代码审查

✅ 未发现问题

likedislike
Rourou2285
Rourou2285
2 天前 评论:

@liyangx 您好,代码经过修改,已经通过ai review。不过现在有一点:我在plugin仓库还有一个pr,在那个pr合并之前这个examples里面会有几个预期失败的测例。在那个pr合并之后我会立马给examples再提一个pr来更新最新结果。

likedislike