HH-442: isolate runtime processes and harden shutdown (#90)

* HH-442: isolate runtime processes and harden shutdown

* HH-442: harden worker shutdown races

* HH-442: gate dependency shutdown on active handlers

---------

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-22 02:38:15 +08:00
committed by GitHub
co-authored by rogee
parent 6d6d80dd86
commit 798ea43c2f
35 changed files with 1673 additions and 451 deletions
+24
View File
@@ -1,10 +1,14 @@
package database
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func TestMigrationCommandsRejectBlankPath(t *testing.T) {
@@ -56,3 +60,23 @@ func TestSanitizePostgresEnvironment(t *testing.T) {
require.False(t, exists, "%s should be removed at application startup", key)
}
}
func TestLatestVersionAndCheckVersion(t *testing.T) {
dir := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(dir, "000001_first.up.sql"), []byte("SELECT 1;"), 0o600))
require.NoError(t, os.WriteFile(filepath.Join(dir, "000012_latest.up.sql"), []byte("SELECT 1;"), 0o600))
require.NoError(t, os.WriteFile(filepath.Join(dir, "README"), nil, 0o600))
latest, err := LatestVersion(dir)
require.NoError(t, err)
require.Equal(t, uint(12), latest)
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
require.NoError(t, err)
require.NoError(t, db.Exec("CREATE TABLE schema_migrations (version INTEGER NOT NULL, dirty BOOLEAN NOT NULL)").Error)
require.NoError(t, db.Exec("INSERT INTO schema_migrations(version, dirty) VALUES (12, false)").Error)
require.NoError(t, CheckVersion(context.Background(), db, latest))
require.Error(t, CheckVersion(context.Background(), db, 13))
require.NoError(t, db.Exec("UPDATE schema_migrations SET dirty = true").Error)
require.ErrorContains(t, CheckVersion(context.Background(), db, latest), "dirty")
}