Files
creator-hub/internal/environment/memory_schema_upgrade_test.go
T
rogee e50bed9ad8
douyin-release-gate / verify (push) Failing after 18m54s
feat: add account events and private message management
Add Douyin notification polling, event details, and manual multi-account private messaging.

Refine environment memory settings, account operations, login collection recovery, and message UI; update tests and documentation.
2026-10-07 10:23:05 +08:00

47 lines
1.8 KiB
Go

package environment
import (
"context"
"os"
"testing"
)
func TestEnvironmentMemorySchemaUpgradeAndRepeatedStartup(t *testing.T) {
databaseURL := os.Getenv("CREATORHUB_POSTGRES_TEST_URL")
if databaseURL == "" {
t.Skip("set CREATORHUB_POSTGRES_TEST_URL")
}
ctx := context.Background()
url := isolatedDatabaseURL(t, databaseURL)
s := openFullyMigratedHub(t, ctx, url)
if _, err := s.CreateGateway(ctx, "memory-upgrade", "http://127.0.0.1:8090", ""); err != nil {
t.Fatal(err)
}
before, err := s.CreateStandaloneEnv(ctx, "memory-upgrade", Fingerprint{Timezone: "Asia/Shanghai"}, 4096)
if err != nil {
t.Fatal(err)
}
// Reproduce a database deployed before 1055 without touching applied scripts.
if _, err := s.db.ExecContext(ctx, `ALTER TABLE browser_env DROP COLUMN memory_limit_mb; DELETE FROM schema_migration WHERE version=1055`); err != nil {
t.Fatal(err)
}
s.Close()
for range 2 {
s = openFullyMigratedHub(t, ctx, url)
after, err := s.GetEnvironmentContext(ctx, before.Alias)
if err != nil || after.MemoryLimitMB != 2048 || after.ID != before.ID || after.ProfileID != before.ProfileID || after.Fingerprint != before.Fingerprint || after.BindingVersion != before.BindingVersion {
t.Fatalf("upgrade changed identity: %+v %v", after, err)
}
assertDatabaseCount(t, s.db, `SELECT count(*) FROM schema_migration WHERE version=1055`, 1)
for _, limit := range []int{511, 65537} {
if _, err := s.db.ExecContext(ctx, `UPDATE browser_env SET memory_limit_mb=$2 WHERE alias=$1`, before.Alias, limit); err == nil {
t.Fatalf("database accepted invalid %d", limit)
}
}
if _, err := s.db.ExecContext(ctx, `UPDATE browser_env SET memory_limit_mb=NULL WHERE alias=$1`, before.Alias); err == nil {
t.Fatal("database accepted null")
}
s.Close()
}
}