mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 07:26:36 +08:00
fix(core): delegate driver and task extension lookups to root context and improve test reliability
This commit is contained in:
+7
-3
@@ -113,12 +113,16 @@ type sharedStore struct {
|
||||
func (s *sharedStore) Tablename() string { return "w_schema_versions" }
|
||||
|
||||
func (s *sharedStore) CreateVersionTable(ctx context.Context, db goosedb.DBTxConn) error {
|
||||
_, err := db.ExecContext(ctx, `CREATE TABLE IF NOT EXISTS w_schema_versions (
|
||||
timeType := "TIMESTAMPTZ"
|
||||
if s.dialect == "sqlite3" || s.dialect == "sqlite" {
|
||||
timeType = "DATETIME"
|
||||
}
|
||||
_, err := db.ExecContext(ctx, fmt.Sprintf(`CREATE TABLE IF NOT EXISTS w_schema_versions (
|
||||
plugin_id VARCHAR(64) NOT NULL,
|
||||
version_id BIGINT NOT NULL,
|
||||
applied_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
applied_at %s NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (plugin_id, version_id)
|
||||
)`)
|
||||
)`, timeType))
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,12 @@ import (
|
||||
|
||||
func TestRedisPluggability_Simulation(t *testing.T) {
|
||||
origRedisEnabled := config.Config.Redis.Enabled
|
||||
defer func() { config.Config.Redis.Enabled = origRedisEnabled }()
|
||||
origAddr := config.Config.App.Addr
|
||||
config.Config.App.Addr = "127.0.0.1:0"
|
||||
defer func() {
|
||||
config.Config.Redis.Enabled = origRedisEnabled
|
||||
config.Config.App.Addr = origAddr
|
||||
}()
|
||||
|
||||
// ══════════════════════════════════════════════════════════════════════════
|
||||
// 场景 1: 拔出 Redis (Zero-Redis Monolith 模式)
|
||||
@@ -174,7 +179,7 @@ func TestRedisPluggability_Simulation(t *testing.T) {
|
||||
|
||||
require.Eventually(t, func() bool {
|
||||
return asynqTaskExecuted.Load() >= 1
|
||||
}, 5*time.Second, 100*time.Millisecond, "Asynq Worker 应从 Redis 队列中成功消费并执行任务")
|
||||
}, 10*time.Second, 100*time.Millisecond, "Asynq Worker 应从 Redis 队列中成功消费并执行任务")
|
||||
|
||||
// 6. 优雅关闭
|
||||
stopCtx, stopCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
|
||||
Reference in New Issue
Block a user