| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "os/exec" |
| 6 | "path/filepath" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | // This subprocess deliberately fails admission. Its fixture must still stop |
| 12 | // the resource owner; registering cleanup after the waiter cannot do that. |
| 13 | func TestCatalogFixtureAdmissionFailureProcess(t *testing.T) { |
| 14 | marker := os.Getenv("REASONIX_TEST_CATALOG_CLEANUP") |
| 15 | if marker == "" { |
| 16 | return |
| 17 | } |
| 18 | done := make(chan struct{}) |
| 19 | close(done) |
| 20 | app := &App{} |
| 21 | app.catalogDone, app.catalogInitialReconcileDone = done, done |
| 22 | app.catalogCancel = func() { |
| 23 | if err := os.WriteFile(marker, []byte("owner stopped"), 0600); err != nil { |
| 24 | t.Error(err) |
| 25 | } |
| 26 | } |
| 27 | waitForInitialCatalogReconcile(t, app) // no published catalog: must fail |
| 28 | } |
| 29 | |
| 30 | func TestCatalogFixtureAdmissionFailureStillStopsOwner(t *testing.T) { |
| 31 | marker := filepath.Join(t.TempDir(), "closed") |
| 32 | cmd := exec.CommandContext(t.Context(), os.Args[0], "-test.run=^TestCatalogFixtureAdmissionFailureProcess$") |
| 33 | cmd.Env = append(os.Environ(), "REASONIX_TEST_CATALOG_CLEANUP="+marker) |
| 34 | output, err := cmd.CombinedOutput() |
| 35 | if err == nil || !strings.Contains(string(output), "session catalog exited before publication") { |
| 36 | t.Fatalf("expected admission failure, got %v: %s", err, output) |
| 37 | } |
| 38 | if got, err := os.ReadFile(marker); err != nil || string(got) != "owner stopped" { |
| 39 | t.Fatalf("failed admission leaked its owner: %q %v", got, err) |
| 40 | } |
| 41 | } |
| 42 |