41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
//go:build live
|
|
|
|
package live
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestPersistedRunningCheckpointMaxDoesNotMissShortWindow(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "checkpoint.db")
|
|
db, err := sql.Open("sqlite", path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer db.Close()
|
|
if _, err = db.Exec(`CREATE TABLE events (conversation_id TEXT, seq INTEGER, type TEXT, payload TEXT)`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for seq, item := range []struct {
|
|
conversation, status, state string
|
|
checkpoint int
|
|
}{
|
|
{"wanted", "active", "running", 1},
|
|
{"other", "active", "running", 9},
|
|
{"wanted", "active", "running", 2},
|
|
{"wanted", "failed", "failed", 99},
|
|
} {
|
|
payload := fmt.Sprintf(`{"card":{"status":%q,"task":{"executionState":%q,"checkpointSeq":%d}}}`, item.status, item.state, item.checkpoint)
|
|
if _, err = db.Exec(`INSERT INTO events(conversation_id,seq,type,payload) VALUES(?,?,?,?)`, item.conversation, seq+1, "card.updated", payload); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
got, err := persistedRunningCheckpointMax(path, "wanted")
|
|
if err != nil || got != 2 {
|
|
t.Fatalf("persisted in-flight checkpoints: max=%d err=%v; want 2", got, err)
|
|
}
|
|
}
|