| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/config" |
| 9 | "reasonix/internal/identitylock" |
| 10 | ) |
| 11 | |
| 12 | func TestHistoricalImportIsExplicitAndSourceBusyDoesNotTakeRuntimeGate(t *testing.T) { |
| 13 | isolateDesktopUserDirs(t) |
| 14 | root := config.SessionStoreDir() |
| 15 | coldV4MigrationFixture(t, root, "on-demand") |
| 16 | app := NewApp() |
| 17 | t.Cleanup(app.closeSessionServices) |
| 18 | list, err := app.ListHistoricalSessions() |
| 19 | if err != nil || len(list.Items) != 1 { |
| 20 | t.Fatalf("discovery: %+v %v", list, err) |
| 21 | } |
| 22 | before := startupHistorySourceBytes(t, root, "on-demand") |
| 23 | release, err := identitylock.Acquire(t.Context(), filepath.Join(root, ".on-demand.ownership.lock")) |
| 24 | if err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | defer release() |
| 28 | _, err = app.ImportHistoricalSession(list.Items[0].ID) |
| 29 | if !errors.Is(err, errHistoricalSourceBusy) { |
| 30 | t.Fatalf("busy source: %v", err) |
| 31 | } |
| 32 | if !app.runtimeRebuildMu.TryLock() { |
| 33 | t.Fatal("historical import retained runtime gate") |
| 34 | } |
| 35 | app.runtimeRebuildMu.Unlock() |
| 36 | release() |
| 37 | result, err := app.ImportHistoricalSession(list.Items[0].ID) |
| 38 | if err != nil || result.Session.SessionID == "" { |
| 39 | t.Fatalf("import: %+v %v", result, err) |
| 40 | } |
| 41 | again, err := app.ImportHistoricalSession(list.Items[0].ID) |
| 42 | if err != nil || again.Session != result.Session { |
| 43 | t.Fatalf("duplicate: %+v %v", again, err) |
| 44 | } |
| 45 | assertStartupHistorySourceUnchanged(t, root, "on-demand", before) |
| 46 | } |
| 47 |