full backup/restore test in a Go test

This commit is contained in:
Matthew Jaffee 2021-12-07 17:12:41 -06:00
parent aff3d3ddd9
commit 3d3080df8b
2 changed files with 43 additions and 2 deletions

View file

@ -92,7 +92,7 @@ func (cmd *ChkSumCommand) Run(ctx context.Context) (err error) {
}
for _, item := range res.Results {
rowids := item.(*pilosa.RowIdentifiers)
//either rowids or keys
// either rowids or keys
for _, row := range rowids.Keys {
countPql := fmt.Sprintf(`Count(Row(%v="%v"))`, field.Name, row)
qr := &pilosa.QueryRequest{Index: ii.Name, Query: countPql}
@ -121,7 +121,7 @@ func (cmd *ChkSumCommand) Run(ctx context.Context) (err error) {
}
}
fmt.Printf("hash:%x\n", h.Sum(nil))
fmt.Fprintf(cmd.Stdout, "hash:%x\n", h.Sum(nil))
}
return nil

View file

@ -7040,6 +7040,35 @@ func backupTest(t *testing.T, c *test.Cluster) {
// putting this here is to take advantage of already-existing
// clusters and data.
sum := chkSumCluster(t, c)
backupDir := backupCluster(t, c)
cnew := test.MustRunCluster(t, 3) // this way we test 1->3 3->3 7->3
defer cnew.Close()
restoreCluster(t, backupDir, cnew)
sumNew := chkSumCluster(t, cnew)
if sum != sumNew {
t.Fatalf("old/new checksum mismatch, old:\n%s\nnew:\n:%s", sum, sumNew)
}
}
func chkSumCluster(t *testing.T, c *test.Cluster) string {
buf := &bytes.Buffer{}
chkSum := ctl.NewChkSumCommand(nil, buf, buf)
chkSum.Host = c.Nodes[len(c.Nodes)-1].URL()
if err := chkSum.Run(context.Background()); err != nil {
t.Fatalf("running checksum: %v", err)
}
return buf.String()
}
func backupCluster(t *testing.T, c *test.Cluster) (backupDir string) {
td, err := testhook.TempDir(t, "backupTest")
if err != nil {
t.Fatalf("can't even get a temp dir, what a ripoff: %v", err)
@ -7056,6 +7085,18 @@ func backupTest(t *testing.T, c *test.Cluster) {
t.Log(buf.String())
t.Fatalf("running backup: %v", err)
}
return td
}
func restoreCluster(t *testing.T, backupDir string, c *test.Cluster) {
buf := &bytes.Buffer{}
restore := ctl.NewRestoreCommand(nil, buf, buf)
restore.Host = c.Nodes[len(c.Nodes)-1].URL()
restore.Path = backupDir
if err := restore.Run(context.Background()); err != nil {
t.Fatalf("restoring: %v", err)
}
}
// tests for abbreviating time values in queries