mirror of
https://github.com/juanfont/headscale.git
synced 2026-10-26 16:26:50 +09:00
servertest: close server state during cleanup
Release the NodeStore and database after clients and background workers stop.
This commit is contained in:
1 parent
54eedce658
commit
543e3b7b08
2 files changed
+18
No files matched your search
@@ -660,3 +660,13 @@ func describeNetmap(c *servertest.TestClient) string {
|
||||
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func TestServerStateCleanup(t *testing.T) {
|
||||
var srv *servertest.TestServer
|
||||
|
||||
t.Run("server", func(t *testing.T) { srv = servertest.NewServer(t) })
|
||||
|
||||
database, err := srv.State().DB().DB.DB()
|
||||
require.NoError(t, err)
|
||||
require.ErrorContains(t, database.Ping(), "database is closed")
|
||||
}
|
||||
@@ -203,6 +203,14 @@ func NewServer(tb testing.TB, opts ...ServerOption) *TestServer {
|
||||
tb.Fatalf("servertest: NewHeadscale: %v", err)
|
||||
}
|
||||
|
||||
// Registered first so clients, HTTP, and background subsystems stop first.
|
||||
tb.Cleanup(func() {
|
||||
err := app.GetState().Close()
|
||||
if err != nil {
|
||||
tb.Errorf("servertest: close state: %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
// Set a minimal DERP map so MapResponse generation works.
|
||||
app.GetState().SetDERPMap(&tailcfg.DERPMap{
|
||||
Regions: map[tailcfg.DERPRegionID]*tailcfg.DERPRegion{
|
||||
|
||||
Reference in new issue
Block a user