-
Notifications
You must be signed in to change notification settings - Fork 0
Pool Controller v2 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| package database | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestPoolConfigV2RebuildPreservesRowsAndForeignKey(t *testing.T) { | ||
| db, err := New(filepath.Join(t.TempDir(), "pool-v2.db")) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| defer db.Close() | ||
| if err := db.Migrate(); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| fn := &Function{Name: "legacy-pool", Runtime: "node", Entrypoint: "handler.js", MemoryMB: 64, CPUs: 1, TimeoutMS: 1000, Status: "active"} | ||
| if err := db.InsertFunction(fn); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| for _, stmt := range []string{ | ||
| `DROP TABLE pool_config`, | ||
| `CREATE TABLE pool_config ( | ||
| function_id TEXT PRIMARY KEY, min_warm INTEGER NOT NULL, max_warm INTEGER NOT NULL, | ||
| idle_ttl_s INTEGER NOT NULL, max_use_count INTEGER NOT NULL, | ||
| target_concurrency INTEGER NOT NULL, scale_to_zero INTEGER NOT NULL, | ||
| FOREIGN KEY (function_id) REFERENCES functions(id) ON DELETE CASCADE)`, | ||
| `INSERT INTO pool_config VALUES ('` + fn.ID + `', 7, 23, 321, 777, 9, 1)`, | ||
| } { | ||
| if _, err := db.write.Exec(stmt); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| if err := db.Migrate(); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| cfg, err := db.GetPoolConfig(fn.ID) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if cfg.MinWarm != 0 || cfg.MaxWarm != 23 || cfg.IdleTTLS != 321 || !cfg.ScaleToZero { | ||
| t.Fatalf("migrated config mismatch: %+v", cfg) | ||
| } | ||
| var targetColumns int | ||
| if err := db.read.QueryRow(`SELECT COUNT(*) FROM pragma_table_info('pool_config') WHERE name='target_concurrency'`).Scan(&targetColumns); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if targetColumns != 0 { | ||
| t.Fatal("target_concurrency survived rebuild") | ||
| } | ||
| if _, err := db.write.Exec(`DELETE FROM functions WHERE id=?`, fn.ID); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| var rows int | ||
| if err := db.read.QueryRow(`SELECT COUNT(*) FROM pool_config WHERE function_id=?`, fn.ID).Scan(&rows); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if rows != 0 { | ||
| t.Fatal("pool_config foreign-key cascade was not preserved") | ||
| } | ||
| } | ||
|
|
||
| func TestPoolConfigNormalization(t *testing.T) { | ||
| db := newTestDB(t) | ||
| fn := &Function{Name: "normalize-pool", Runtime: "node", Entrypoint: "handler.js", MemoryMB: 64, CPUs: 1, TimeoutMS: 1000, Status: "active"} | ||
| if err := db.InsertFunction(fn); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| cfg := &PoolConfig{FunctionID: fn.ID, MinWarm: 4, MaxWarm: 10, IdleTTLS: 600, ScaleToZero: true} | ||
| if err := db.UpsertPoolConfig(cfg); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if got, _ := db.GetPoolConfig(fn.ID); got.MinWarm != 0 { | ||
| t.Fatalf("scale-to-zero min=%d", got.MinWarm) | ||
| } | ||
| cfg.ScaleToZero = false | ||
| if err := db.UpsertPoolConfig(cfg); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if got, _ := db.GetPoolConfig(fn.ID); got.MinWarm != 1 { | ||
| t.Fatalf("active min=%d", got.MinWarm) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upgrading any database that still has
target_concurrencyexecutes thisDROP TABLE pool_config, despite the repository's explicit additive-only migration invariant. The controller can simply leave the now-unused column in place and normalizemin_warmwith an idempotentUPDATE; rebuilding the table also removes independently added indexes or triggers and makes downgrade compatibility unnecessarily unsafe.AGENTS.md reference: backend/AGENTS.md:L87-L89
Useful? React with 👍 / 👎.