0c9f256dfc
对应体检报告 #10-#24,一次性完成 v1.1.0 全部 13 项: - #10 storage/cache/redis/jwt/logger 五组件 Manager 化(XxxManager + DefaultXxx + SetDefaultXxxManager,包级 facade 保留兼容) - #11 删除 wire 包 + 清理 StartServerWithPort/GracefulShutdown 双轨 - #12 Lifecycle Hooks(OnInit/OnStart/OnReady/OnStop) - #13 Server 参数配置化(timeout/TLS/unix_socket/response_mode) - #14 JWTConfig.Expire 改 time.Duration + 删 AppConfig.TokenExpire - #15 response Mode 开关(ModeBusiness/ModeREST) - #16 Config.Validate 启动期校验 - #17 livez/readyz 探针路由 - #18 Prometheus metrics 中间件 + /metrics - #19 请求级 Timeout 中间件 - #21 主库探活 + replica 健康剔除 - #22 App.Go + in-flight goroutine 管理 - #24 RequestID 默认装入 + #23 核对 Breaking:删 wire、删 TokenExpire、JWTConfig.Expire 类型变更、删双轨函数。 详见 CHANGELOG 升级说明。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
44 lines
876 B
Go
44 lines
876 B
Go
package xlgo_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
xlgo "github.com/EthanCodeCraft/xlgo-core"
|
|
)
|
|
|
|
func TestAppGoWaitsOnShutdown(t *testing.T) {
|
|
app := xlgo.New()
|
|
|
|
started := make(chan struct{})
|
|
exited := make(chan struct{})
|
|
app.Go(func(ctx context.Context) {
|
|
close(started)
|
|
<-ctx.Done()
|
|
// 模拟收尾
|
|
time.Sleep(10 * time.Millisecond)
|
|
close(exited)
|
|
})
|
|
|
|
<-started
|
|
|
|
// Shutdown 应 cancel ctx 并等待 goroutine 退出
|
|
done := make(chan error, 1)
|
|
go func() { done <- app.Shutdown() }()
|
|
select {
|
|
case <-exited:
|
|
// goroutine 在 cancel 后退出,符合预期
|
|
case <-time.After(2 * time.Second):
|
|
t.Fatal("App.Go goroutine did not exit after Shutdown cancel")
|
|
}
|
|
select {
|
|
case err := <-done:
|
|
if err != nil {
|
|
t.Errorf("Shutdown returned error: %v", err)
|
|
}
|
|
case <-time.After(2 * time.Second):
|
|
t.Fatal("Shutdown did not return")
|
|
}
|
|
}
|