Skip to content

[Bug Report] CubeMaster integration test package panics: dao: Open has not been called yet #1372

Description

@aptacc2421

Summary

CubeMaster's integration test package panics at TestMain on current master: pkg/base/db.Init now
requires the shared dao.Open handle to be established first, but the test still initializes mocks
before the app starts.

Environment

  • CubeSandbox version / commit: master @ 0daf59a (2026-08-18)
  • Host OS and kernel version: N/A (test-only; reproduces on any host with Go >= 1.25)
  • KVM info (modinfo kvm): N/A
  • Deployment mode: N/A (does not affect deployments; only the integration test package)
  • Relevant component: CubeMaster (integration test package) / CubeDB (dao)

Steps to Reproduce

  1. Check out master at 0daf59a.
  2. Save the following config as repro.yaml (the log section is required by config validation):

common:
http_port: 18089
http_bind: "127.0.0.1"
log:
path: "/tmp/cm-log"
file_size: 100
file_num: 10
level: "info"
instance_db_config:
addr: "127.0.0.1:3306"
user: "root"
pwd: "root"
db_name: "test"
redis:
nodes: "127.0.0.1:6379"

  1. Run (no MySQL/Redis needed to trigger):

cd CubeMaster
mkdir -p /tmp/cm-log
CUBE_MASTER_CONFIG_PATH=$PWD/repro.yaml go test ./integration/ -run TestDemo -count=1

Expected Behavior

TestMain should open the shared database handle (as app.Run does via dao.Open) before any package
touches it, so the integration tests can start (with a reachable MySQL/Redis) instead of panicking.

Actual Behavior

panic: dao: Open has not been called yet

goroutine 1 [running]:
github.com/tencentcloud/CubeSandbox/CubeDB/dao.Default()
CubeDB/dao/dao.go:143 +0xc7
github.com/tencentcloud/CubeSandbox/CubeMaster/pkg/base/db.Init(...)
CubeMaster/pkg/base/db/db.go:21
github.com/tencentcloud/CubeSandbox/CubeMaster/integration.mock_db(...)
CubeMaster/integration/mock_init.go:657
github.com/tencentcloud/CubeSandbox/CubeMaster/integration.MockInit()
CubeMaster/integration/mock_init.go:111 +0x2c
github.com/tencentcloud/CubeSandbox/CubeMaster/integration.TestMain(...)
CubeMaster/integration/main_test.go:33 +0x85
main.main()
_testmain.go:66 +0xa5
FAIL github.com/tencentcloud/CubeSandbox/CubeMaster/integration

Additional Context

  • Root cause: PR Decoupling of CubeAPI Operations Logic and Architecture Refactoring #984 ("Decoupling of CubeAPI Operations Logic and Architecture Refactoring")
    changed pkg/base/db.Init into a thin wrapper that returns dao.Default() — the connection is
    established by dao.Open at app startup — but integration.TestMain still calls MockInit() before
    app.Run() (where dao.Open runs), so dao.Default() is reached before the handle exists.

  • The package is excluded from the regular unit-test CI job (make test greps out /integration), and
    the Makefile integration-test target references a test/conf.yaml that is not present in the repo,
    so CI does not catch this.

  • Suggested fix: in integration/main_test.go, call dao.Open(ctx, ...) (from config.GetDbConfig())
    before MockInit(); dao.Open is idempotent, so the later app.Run() open is a no-op. Optionally
    follow with dao.Migrate(ctx).

  • Reproducing requires a log section in the config; a minimal config without it fails config
    validation first (validate config fail: log config is nil).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions