Artifact c29c46033a2f70479e5df89b06bbdac7de51db5bc3b0e23b4d25e5c634794c96:
- File
internal/oltp/repostate_test.go
— part of check-in
[58c34af8f6]
at
2026-08-30 13:18:09
on branch trunk
— imports are visible: a cloning repository exists from the first second
repo.add registers the row, returns, and copies behind it. State is cloning until the store lands, failed with the reason if it does not, and a restart settles rows it interrupted rather than leaving them claiming to clone forever. The fleet page grows an Importing section. (user: dmestas, size: 2144) [annotate] [blame] [check-ins using]
package oltp import "testing" // An import is registered before it is copied, so the repository exists // while it fills. The states have to survive that round trip, and a // failure has to keep its reason — an import that vanished without // saying why is the thing this replaces. func TestImportStatesRoundTrip(t *testing.T) { d := testDB(t) if err := d.AddImportingRepo("tk", "/tmp/tk", "Tk GUI toolkit", Public, "https://core.tcl-lang.org/tk"); err != nil { t.Fatal(err) } r, ok, err := d.RepoByName("tk") if err != nil || !ok { t.Fatalf("not registered: ok=%v err=%v", ok, err) } if r.State != Cloning || r.ImportURL != "https://core.tcl-lang.org/tk" { t.Fatalf("state %q url %q, want cloning and the upstream", r.State, r.ImportURL) } // Listed as in-flight, which is what the startup sweep reads. names, err := d.ImportingRepos() if err != nil || len(names) != 1 || names[0] != "tk" { t.Fatalf("importing = %v (err %v), want [tk]", names, err) } if err := d.SetRepoState("tk", Failed, "connection reset"); err != nil { t.Fatal(err) } if r, _, _ = d.RepoByName("tk"); r.State != Failed || r.ImportError != "connection reset" { t.Fatalf("state %q error %q, want failed and the reason", r.State, r.ImportError) } // Succeeding on a retry must not keep explaining a failure that no // longer applies. if err := d.SetRepoState("tk", Ready, ""); err != nil { t.Fatal(err) } if r, _, _ = d.RepoByName("tk"); r.State != Ready || r.ImportError != "" { t.Fatalf("state %q error %q, want ready and no error", r.State, r.ImportError) } if names, _ := d.ImportingRepos(); len(names) != 0 { t.Errorf("a ready repository is still listed as importing: %v", names) } } // A repository added the ordinary way is Ready, so every row written // before importing existed reads correctly. func TestPlainRepoIsReady(t *testing.T) { d := testDB(t) if err := d.AddRepo("quarry", "/tmp/quarry", "", Public); err != nil { t.Fatal(err) } r, ok, err := d.RepoByName("quarry") if err != nil || !ok { t.Fatalf("ok=%v err=%v", ok, err) } if r.State != Ready { t.Errorf("state %q, want ready", r.State) } }