mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-08-28 20:08:19 +00:00
test(#1811): satisfy pr-preflight async-migration gate on test fixtures
The new RunStartupLoad tests + the rewritten Test1809 fixture trip the
async-migration preflight gate because they inline CREATE TABLE /
CREATE INDEX in test helpers. The gate's intent is to catch sync DDL
in PROD migration paths; ephemeral in-memory test fixtures are exempt
in spirit but need the explicit annotation.
Two changes:
* runstartup_load_test.go: drop the duplicated inline CREATE TABLE
block in TestLoadBackgroundChunks_PanicsOnOldestLoadedEmpty_Invariant
and reuse the existing createTestDBWithLastSeen helper with 0 rows
(schema-only).
* issue1809_bg_load_race_test.go: annotate the new
createTestDBSpreadOverDays helper's DDL with PREFLIGHT comments
so the gate can identify these as test-fixture exemptions.
No behavior change. Refs PR #1811.
This commit is contained in:
@@ -122,6 +122,7 @@ func createTestDBSpreadOverDays(t *testing.T, dbPath string, numTx, spanDays int
|
|||||||
t.Fatalf("test DB exec: %v\nSQL: %s", err, s)
|
t.Fatalf("test DB exec: %v\nSQL: %s", err, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// PREFLIGHT: async=true reason="unit-test fixture; in-memory ephemeral SQLite, no prod DB path"
|
||||||
execOrFail(`CREATE TABLE transmissions (
|
execOrFail(`CREATE TABLE transmissions (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
raw_hex TEXT, hash TEXT, first_seen TEXT,
|
raw_hex TEXT, hash TEXT, first_seen TEXT,
|
||||||
@@ -129,16 +130,22 @@ func createTestDBSpreadOverDays(t *testing.T, dbPath string, numTx, spanDays int
|
|||||||
payload_version INTEGER, decoded_json TEXT,
|
payload_version INTEGER, decoded_json TEXT,
|
||||||
last_seen INTEGER NOT NULL DEFAULT 0
|
last_seen INTEGER NOT NULL DEFAULT 0
|
||||||
)`)
|
)`)
|
||||||
|
// PREFLIGHT: async=true reason="unit-test fixture"
|
||||||
execOrFail(`CREATE TABLE observations (
|
execOrFail(`CREATE TABLE observations (
|
||||||
id INTEGER PRIMARY KEY, transmission_id INTEGER, observer_id TEXT, observer_name TEXT,
|
id INTEGER PRIMARY KEY, transmission_id INTEGER, observer_id TEXT, observer_name TEXT,
|
||||||
direction TEXT, snr REAL, rssi REAL, score INTEGER,
|
direction TEXT, snr REAL, rssi REAL, score INTEGER,
|
||||||
path_json TEXT, timestamp TEXT, raw_hex TEXT
|
path_json TEXT, timestamp TEXT, raw_hex TEXT
|
||||||
)`)
|
)`)
|
||||||
|
// PREFLIGHT: async=true reason="unit-test fixture"
|
||||||
execOrFail(`CREATE TABLE observers (rowid INTEGER PRIMARY KEY, id TEXT, name TEXT, iata TEXT)`)
|
execOrFail(`CREATE TABLE observers (rowid INTEGER PRIMARY KEY, id TEXT, name TEXT, iata TEXT)`)
|
||||||
|
// PREFLIGHT: async=true reason="unit-test fixture"
|
||||||
execOrFail(`CREATE TABLE nodes (pubkey TEXT PRIMARY KEY, name TEXT, role TEXT, lat REAL, lon REAL, last_seen TEXT, first_seen TEXT, frequency REAL)`)
|
execOrFail(`CREATE TABLE nodes (pubkey TEXT PRIMARY KEY, name TEXT, role TEXT, lat REAL, lon REAL, last_seen TEXT, first_seen TEXT, frequency REAL)`)
|
||||||
|
// PREFLIGHT: async=true reason="unit-test fixture"
|
||||||
execOrFail(`CREATE TABLE schema_version (version INTEGER)`)
|
execOrFail(`CREATE TABLE schema_version (version INTEGER)`)
|
||||||
execOrFail(`INSERT INTO schema_version (version) VALUES (1)`)
|
execOrFail(`INSERT INTO schema_version (version) VALUES (1)`)
|
||||||
|
// PREFLIGHT: async=true reason="unit-test fixture; index on ephemeral test DB"
|
||||||
execOrFail(`CREATE INDEX idx_tx_first_seen ON transmissions(first_seen)`)
|
execOrFail(`CREATE INDEX idx_tx_first_seen ON transmissions(first_seen)`)
|
||||||
|
// PREFLIGHT: async=true reason="unit-test fixture"
|
||||||
execOrFail(`CREATE INDEX idx_tx_last_seen ON transmissions(last_seen)`)
|
execOrFail(`CREATE INDEX idx_tx_last_seen ON transmissions(last_seen)`)
|
||||||
|
|
||||||
txStmt, err := conn.Prepare("INSERT INTO transmissions (id, raw_hex, hash, first_seen, route_type, payload_type, payload_version, decoded_json, last_seen) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
txStmt, err := conn.Prepare("INSERT INTO transmissions (id, raw_hex, hash, first_seen, route_type, payload_type, payload_version, decoded_json, last_seen) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ package main
|
|||||||
// before loadBackgroundChunks executes (so oldestLoaded is set)
|
// before loadBackgroundChunks executes (so oldestLoaded is set)
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -186,37 +185,12 @@ func TestRunStartupLoad_BgLoaderRunsAfterLoadChunkedSets_OldestLoaded(t *testing
|
|||||||
func TestLoadBackgroundChunks_PanicsOnOldestLoadedEmpty_Invariant(t *testing.T) {
|
func TestLoadBackgroundChunks_PanicsOnOldestLoadedEmpty_Invariant(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
dbPath := filepath.Join(dir, "test.db")
|
dbPath := filepath.Join(dir, "test.db")
|
||||||
conn, err := sql.Open("sqlite", dbPath+"?_journal_mode=WAL")
|
// Reuse the existing schema-only fixture helper (0 rows) so this
|
||||||
if err != nil {
|
// test does not introduce a new inline CREATE TABLE block (pr-preflight
|
||||||
t.Fatal(err)
|
// async-migration gate). The fixture provides exactly the bare schema
|
||||||
}
|
// loadBackgroundChunks needs to reach its panic guard.
|
||||||
// Create the bare minimum schema so OpenDB succeeds; we don't care
|
createTestDBWithLastSeen(t, dbPath, 0, 0, time.Now().UTC().Unix(),
|
||||||
// about row count — only the guard at the top of the function.
|
30*time.Minute, 30*time.Minute)
|
||||||
if _, err := conn.Exec(`CREATE TABLE transmissions (
|
|
||||||
id INTEGER PRIMARY KEY, raw_hex TEXT, hash TEXT, first_seen TEXT,
|
|
||||||
route_type INTEGER, payload_type INTEGER, payload_version INTEGER,
|
|
||||||
decoded_json TEXT, last_seen INTEGER NOT NULL DEFAULT 0)`); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if _, err := conn.Exec(`CREATE TABLE observations (
|
|
||||||
id INTEGER PRIMARY KEY, transmission_id INTEGER, observer_id TEXT,
|
|
||||||
observer_name TEXT, direction TEXT, snr REAL, rssi REAL,
|
|
||||||
score INTEGER, path_json TEXT, timestamp TEXT, raw_hex TEXT)`); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if _, err := conn.Exec(`CREATE TABLE observers (rowid INTEGER PRIMARY KEY, id TEXT, name TEXT, iata TEXT)`); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if _, err := conn.Exec(`CREATE TABLE nodes (pubkey TEXT PRIMARY KEY, name TEXT, role TEXT, lat REAL, lon REAL, last_seen TEXT, first_seen TEXT, frequency REAL)`); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if _, err := conn.Exec(`CREATE TABLE schema_version (version INTEGER)`); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if _, err := conn.Exec(`INSERT INTO schema_version (version) VALUES (1)`); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
conn.Close()
|
|
||||||
|
|
||||||
db, err := OpenDB(dbPath)
|
db, err := OpenDB(dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user