Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions scripts/test_databases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
set -euo pipefail

if [[ $# -lt 1 || $# -gt 2 ]]; then
printf 'Usage: %s BUILD_DIR [local|redis|mysql|redis-awaitable|mysql-awaitable|all]\n' "$0" >&2
printf 'Usage: %s BUILD_DIR [local|redis|mysql|redis-awaitable|mysql-awaitable|public-redis|public-mysql|public-services|all]\n' "$0" >&2
exit 2
fi

database_test_dir=$(cd -- "$1" && pwd)/tests/database
database_test_mode=${2:-local}
case "$database_test_mode" in
local|redis|mysql|redis-awaitable|mysql-awaitable|all) ;;
local|redis|mysql|redis-awaitable|mysql-awaitable|public-redis|public-mysql|public-services|all) ;;
*) printf 'Unknown database test mode: %s\n' "$database_test_mode" >&2; exit 2 ;;
esac

Expand Down Expand Up @@ -50,3 +50,9 @@ fi
if [[ "$database_test_mode" == mysql-awaitable || "$database_test_mode" == all ]]; then
run_database_test ark_database_service_awaitable_tests mysql
fi
if [[ "$database_test_mode" == public-redis || "$database_test_mode" == public-services || "$database_test_mode" == all ]]; then
run_database_test ark_database_public_service_tests redis
fi
if [[ "$database_test_mode" == public-mysql || "$database_test_mode" == public-services || "$database_test_mode" == all ]]; then
run_database_test ark_database_public_service_tests mysql
fi
11 changes: 9 additions & 2 deletions tests/database/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Development-only native database bridges; no runtime plugin is enabled here.
# Development-only database checks; no runtime application plugin is enabled here.
find_package(Threads REQUIRED)
if(NOT EXISTS "${ARKNET_SOURCE_DIR}/include/arknet/redis/pool.hpp")
message(FATAL_ERROR "Database development tests require a local arknet checkout with the native Redis pool")
Expand Down Expand Up @@ -36,6 +36,10 @@ target_link_libraries(ark_database_redis_stop_tests PRIVATE arknet::arknet)
ark_database_test(ark_database_public_redis_tests main.cpp public_redis_module.cpp
"${ROOT_DIR}/src/plugins/redis/redis_module_impl.cpp")
target_link_libraries(ark_database_public_redis_tests PRIVATE ark::core arknet::arknet)
# Explicit real-service acceptance; deliberately excluded from check-database.
ark_database_test(ark_database_public_service_tests public_service.cpp
"${ROOT_DIR}/src/plugins/redis/redis_module_impl.cpp")
target_link_libraries(ark_database_public_service_tests PRIVATE ark::core arknet::arknet)
add_library(ark_database_redis_plugin SHARED
"${ROOT_DIR}/src/plugins/redis/redis_plugin.cpp" "${ROOT_DIR}/src/plugins/redis/redis_module_impl.cpp")
target_include_directories(ark_database_redis_plugin PRIVATE "${ROOT_DIR}/src/plugins")
Expand Down Expand Up @@ -67,9 +71,12 @@ add_custom_target(check-database
ark_database_task_contract_tests
USES_TERMINAL)

add_dependencies(check-database ark_database_redis_sample_check)
# Compile real-service acceptance in ordinary CI without running any server work.
add_dependencies(check-database ark_database_redis_sample_check ark_database_public_service_tests)

if(ARKNET_ENABLE_SSL)
target_sources(ark_database_public_service_tests PRIVATE
"${ROOT_DIR}/src/plugins/mysql/mysql_module_impl.cpp")
target_compile_definitions(ark_database_public_redis_tests PRIVATE
ARK_DATABASE_REDIS_CERT_DIR="${ARKNET_SOURCE_DIR}/tests/certs")
ark_database_test(ark_database_public_mysql_tests main.cpp public_mysql_module.cpp
Expand Down
52 changes: 52 additions & 0 deletions tests/database/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,55 @@ peers. `ark_database_public_redis_plugin_tests` and
`ark_database_public_mysql_plugin_tests` load actual hidden-symbol plugin
libraries. The migrated samples are also compiled by `check-database`. MySQL
checks require SSL; real-server targets still require explicit endpoint settings.

## Public modules against real services

`ark_database_public_service_tests` calls the public `mysql_module` and
`redis_module` interfaces with their real implementations, a registered consumer's
`task_group`, and the manager's shared `manual_runtime`. It is a separate C++
executable; `check-database` compiles it without running it or connecting to a server.

```sh
cmake --build database-build --target ark_database_public_service_tests --parallel 2
# Configure the isolated endpoints first, then choose either protocol or both.
bash scripts/test_databases.sh database-build public-redis
bash scripts/test_databases.sh database-build public-mysql
bash scripts/test_databases.sh database-build public-services
# Equivalent direct invocations:
./database-build/tests/database/ark_database_public_service_tests redis
./database-build/tests/database/ark_database_public_service_tests mysql
```

Redis requires `ARK_DATABASE_REDIS_HOST` and `ARK_DATABASE_REDIS_PORT`. Optional
`ARK_DATABASE_REDIS_USER` and `ARK_DATABASE_REDIS_PASSWORD` configure authentication;
use an authenticated disposable service to verify that path. The check mutates the
caller's configuration after registration, verifies an ordered binary ECHO/ECHO/PING
pipeline and a follow-up command, and makes no writes.

MySQL requires `ARK_DATABASE_MYSQL_HOST`, `ARK_DATABASE_MYSQL_PORT`,
`ARK_DATABASE_MYSQL_USER`, `ARK_DATABASE_MYSQL_PASSWORD` (present, possibly empty),
`ARK_DATABASE_MYSQL_DATABASE` and `ARK_DATABASE_MYSQL_CA`. TLS and peer verification
are required. Use a disposable schema and an account with CREATE, DROP, SELECT and
INSERT privileges. The check creates a unique `ark_public_service_...` InnoDB
table, exercises text queries, binary prepared results, transaction queries and
prepared inserts, then verifies committed data and the absence of rolled-back
data. It drops its table after the workflow, including assertion failures when the
connection remains usable. A failed connection, active transaction cleanup, or
forced process exit can leave the table for disposable-schema cleanup.

Both protocols assert owner-thread/shared-executor coroutine resumption, input and
configuration ownership, and result ownership after subsequent operations and
module/runtime destruction. The manager enters natural drain with accepted work
pending; follow-up requests finish before successful, idempotent stop. There is no
cancellation or service fault injection in these real-service cases. Each protocol
also repeats its workflow with deliberate host-stack unwinding while IO is pending:
named coroutine functions own their input values, the owner destructor drains the
workflow, and the outer scope verifies its completion and retained results.
Protocol-peer and DSO regressions remain separate checks; these results do not establish dynamic-library
unloading, failure recovery or capacity acceptance.

The executable requires explicit endpoints, returns nonzero for missing/invalid
configuration or failure, and does not print credentials or arbitrary native error
messages. It never starts or stops servers. `all` also includes both public
real-service modes and therefore requires an SSL-enabled build and both endpoint
configurations.
42 changes: 42 additions & 0 deletions tests/database/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,45 @@ bash scripts/test_databases.sh database-build redis
验证拥有型结果、取消、TLS 与正常停机。`ark_database_public_redis_plugin_tests` 和
`ark_database_public_mysql_plugin_tests` 加载实际隐藏符号动态库。
`check-database` 还编译迁移后的示例。MySQL 检查要求开启 SSL,真实服务目标仍需显式配置端点。

## 公开模块真实服务验收

`ark_database_public_service_tests` 通过公开的 `mysql_module`、`redis_module`
接口调用真实实现,使用已注册消费模块的 `task_group` 和管理器共享的
`manual_runtime`。这是独立的 C++ 可执行程序;`check-database` 仅编译此程序,不运行,也不连接服务。

```sh
cmake --build database-build --target ark_database_public_service_tests --parallel 2
# 先配置隔离服务的端点,再选择一种协议或同时运行两种协议。
bash scripts/test_databases.sh database-build public-redis
bash scripts/test_databases.sh database-build public-mysql
bash scripts/test_databases.sh database-build public-services
# 也可以直接运行:
./database-build/tests/database/ark_database_public_service_tests redis
./database-build/tests/database/ark_database_public_service_tests mysql
```

Redis 要求设置 `ARK_DATABASE_REDIS_HOST` 和 `ARK_DATABASE_REDIS_PORT`。
可选的 `ARK_DATABASE_REDIS_USER`、`ARK_DATABASE_REDIS_PASSWORD` 用于认证;
验证认证路径时,需使用启用了认证的临时服务。测试在注册后修改调用方配置,
验证有序的二进制 ECHO/ECHO/PING 流水线及后续命令,不执行写入。

MySQL 要求设置 `ARK_DATABASE_MYSQL_HOST`、`ARK_DATABASE_MYSQL_PORT`、
`ARK_DATABASE_MYSQL_USER`、`ARK_DATABASE_MYSQL_PASSWORD`(必须存在,可以为空)、
`ARK_DATABASE_MYSQL_DATABASE` 和 `ARK_DATABASE_MYSQL_CA`。连接必须使用 TLS 并验证证书。
使用临时数据库,以及具备 CREATE、DROP、SELECT、INSERT 权限的账号。
测试创建唯一的 `ark_public_service_...` InnoDB 表,执行文本查询、二进制预处理查询、
事务查询和预处理插入,再验证提交数据可见、回滚数据不可见。流程结束后删除测试表;
断言失败且连接仍可用时,也会尝试删除。连接失败、活动事务清理或强制退出进程可能留下测试表,
需随临时数据库一起清理。

两种协议均检查协程在拥有线程及共享执行器上恢复、输入与配置的所有权,以及后续操作和
模块/运行时销毁后结果仍然有效。管理器在已受理任务等待期间进入自然排空状态,
允许流程完成后续请求,再验证成功且可重复调用的停止操作。每种协议还会在 IO 等待期间主动
触发宿主栈展开并重复整个流程:命名协程函数按值拥有输入,拥有者析构时排空流程,外层作用域
再验证完成结果与保留的数据。这些真实服务用例不注入服务故障,也不测试取消。协议端点回归和动态库回归仍是独立检查;此处结果不代表动态库卸载、
故障恢复或容量验收。

程序必须显式配置端点;配置缺失、无效或验收失败均返回非零状态,不打印凭据或任意原生错误文本,
也不会启动或停止服务。`all` 也运行这两种公开模块真实服务模式,因此要求启用 SSL,
并配置两种服务的端点。
Loading
Loading