Improve dashboard health and state recovery
This commit is contained in:
1 parent
819055cbf0
commit
8f75a04db6
15 files changed
+313
-38
No files matched your search
@@ -2,6 +2,7 @@ package store
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -30,6 +31,49 @@ func TestStoreInitializesAndPersists(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorruptRunHistoryIsQuarantinedBeforeReplacement(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
s := New(dir)
|
||||
if err := os.WriteFile(s.runsPath(), []byte(`{"broken":`), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.LoadRuns(); err == nil {
|
||||
t.Fatal("corrupt run history loaded without error")
|
||||
}
|
||||
if _, err := os.Stat(s.runsPath()); !os.IsNotExist(err) {
|
||||
t.Fatalf("corrupt runs file was not moved: %v", err)
|
||||
}
|
||||
matches, err := filepath.Glob(s.runsPath() + ".corrupt-*")
|
||||
if err != nil || len(matches) != 1 {
|
||||
t.Fatalf("quarantined run files = %#v, %v", matches, err)
|
||||
}
|
||||
if err := s.SaveRuns([]model.Run{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(matches[0]); err != nil {
|
||||
t.Fatalf("quarantined run file was overwritten: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCorruptBackupMetricsAreQuarantined(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
s := New(dir)
|
||||
if err := os.WriteFile(s.backupMetricsPath(), []byte("{not-json}\n"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, _, err := s.LoadBackupMetrics(); err == nil {
|
||||
t.Fatal("corrupt backup metrics loaded without error")
|
||||
}
|
||||
matches, err := filepath.Glob(s.backupMetricsPath() + ".corrupt-*")
|
||||
if err != nil || len(matches) != 1 {
|
||||
t.Fatalf("quarantined metric files = %#v, %v", matches, err)
|
||||
}
|
||||
contents, err := os.ReadFile(matches[0])
|
||||
if err != nil || string(contents) != "{not-json}\n" {
|
||||
t.Fatalf("quarantined metric contents = %q, %v", contents, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBackupMetricsPersistSeparatelyFromRuns(t *testing.T) {
|
||||
s := New(t.TempDir())
|
||||
if err := s.Init(); err != nil {
|
||||
|
||||
Reference in new issue
Block a user