Skip to content

Commit 04922ec

Browse files
committed
test(1-1-restore): adjusts tests for 1-1-restore progress
1 parent 35801cd commit 04922ec

36 files changed

+563
-835
lines changed

Diff for: pkg/service/one2onerestore/progress_integration_test.go

+71-116
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import (
1010
"os"
1111
"testing"
1212

13-
"github.com/scylladb/scylla-manager/v3/pkg/scyllaclient"
1413
"github.com/scylladb/scylla-manager/v3/pkg/service/backup/backupspec"
1514
"github.com/scylladb/scylla-manager/v3/pkg/testutils"
1615
"github.com/scylladb/scylla-manager/v3/pkg/testutils/db"
1716
"github.com/scylladb/scylla-manager/v3/pkg/testutils/testconfig"
18-
"github.com/scylladb/scylla-manager/v3/pkg/util/timeutc"
1917
"github.com/scylladb/scylla-manager/v3/pkg/util/uuid"
2018
)
2119

@@ -65,172 +63,129 @@ func TestGetProgressIntegration(t *testing.T) {
6563
if err != nil {
6664
t.Fatalf("Unexpected err, prepareHostWorkload: %v", err)
6765
}
68-
69-
testutils.Print("ALTER_TGC Stage")
70-
err = w.setTombstoneGCModeRepair(context.Background(), workload)
66+
pr, err := w.getProgress(context.Background())
7167
if err != nil {
72-
t.Fatalf("Unexpected err, setTombstoneGCModeRepair: %v", err)
68+
t.Fatalf("Unexpected err, getProgress: %v", err)
7369
}
70+
if !progressIsEmpty(pr) {
71+
t.Fatalf("Expected empty progress, but got: %v", pr)
72+
}
73+
74+
w.initProgress(context.Background(), workload)
7475

75-
pr, err := w.getProgress(context.Background(), target)
76+
pr, err = w.getProgress(context.Background())
7677
if err != nil {
7778
t.Fatalf("Unexpected err, getProgress: %v", err)
7879
}
79-
if pr.Stage != StageAlterTGC {
80-
t.Fatalf("Expected stage ALTER_TGC, but got %s", pr.Stage)
80+
if progressIsEmpty(pr) {
81+
t.Fatalf("Expected not empty progress, but got empty")
8182
}
82-
validateKeyspaces(t, pr.Keyspaces)
83+
expectProgressStatus(t, pr, ProgressStatusNotStarted)
8384

84-
testutils.Print("DROP_VIEWS Stage")
85-
views, err := w.dropViews(context.Background(), workload)
85+
testutils.Print("ALTER_TGC Stage")
86+
err = w.setTombstoneGCModeRepair(context.Background(), workload)
8687
if err != nil {
87-
t.Fatalf("Unexpected err, dropViews: %v", err)
88+
t.Fatalf("Unexpected err, setTombstoneGCModeRepair: %v", err)
8889
}
8990

90-
pr, err = w.getProgress(context.Background(), target)
91+
testutils.Print("DROP_VIEWS Stage")
92+
views, err := w.dropViews(context.Background(), workload)
9193
if err != nil {
92-
t.Fatalf("Unexpected err, getProgress: %v", err)
93-
}
94-
if pr.Stage != StageDropViews {
95-
t.Fatalf("Expected stage DROP_VIEW, but got %s", pr.Stage)
94+
t.Fatalf("Unexpected err, dropViews: %v", err)
9695
}
97-
validateViews(t, pr.Views, "")
9896

9997
testutils.Print("DATA Stage")
10098
if err := w.restoreTables(context.Background(), workload, target.Keyspace); err != nil {
10199
t.Fatalf("Unexpected err, restoreTables: %v", err)
102100
}
103-
pr, err = w.getProgress(context.Background(), target)
101+
102+
pr, err = w.getProgress(context.Background())
104103
if err != nil {
105104
t.Fatalf("Unexpected err, getProgress: %v", err)
106105
}
107-
if pr.Stage != StageData {
108-
t.Fatalf("Expected stage DATA, but got %s", pr.Stage)
106+
if progressIsEmpty(pr) {
107+
t.Fatalf("Expected not empty progress, but got empty")
109108
}
110-
validateKeyspaces(t, pr.Keyspaces)
111-
validateHosts(t, pr.Hosts)
109+
expectTablesStatus(t, pr.Tables, ProgressStatusDone)
110+
expectViewsStatus(t, pr.Views, ProgressStatusNotStarted)
112111

113112
testutils.Print("RECREATE_VIEWS Stage")
114113
if err := w.reCreateViews(context.Background(), views); err != nil {
115114
t.Fatalf("Unexpected err, reCreateViews: %v", err)
116115
}
117-
pr, err = w.getProgress(context.Background(), target)
116+
117+
pr, err = w.getProgress(context.Background())
118118
if err != nil {
119119
t.Fatalf("Unexpected err, getProgress: %v", err)
120120
}
121-
if pr.Stage != StageRecreateViews {
122-
t.Fatalf("Expected stage RECREATE_VIEW, but got %s", pr.Stage)
121+
if progressIsEmpty(pr) {
122+
t.Fatalf("Expected not empty progress, but got empty")
123123
}
124-
validateViews(t, pr.Views, scyllaclient.StatusSuccess)
124+
expectProgressStatus(t, pr, ProgressStatusDone)
125+
}
125126

126-
testutils.Print("DONE Stage")
127-
w.progressDone(context.Background(), timeutc.Now(), timeutc.Now())
128-
pr, err = w.getProgress(context.Background(), target)
129-
if err != nil {
130-
t.Fatalf("Unexpected err, getProgress: %v", err)
131-
}
132-
validateGetProgress(t, pr, snapshotTag)
127+
func progressIsEmpty(pr Progress) bool {
128+
return len(pr.Tables) == 0 && len(pr.Views) == 0
133129
}
134130

135-
func validateGetProgress(t *testing.T, pr Progress, tag string) {
131+
func expectProgressStatus(t *testing.T, pr Progress, status ProgressStatus) {
136132
t.Helper()
137-
if pr.SnapshotTag != tag {
138-
t.Fatalf("Expected snapshot tag %s, but got %s", tag, pr.SnapshotTag)
139-
}
140-
if pr.Stage != StageDone {
141-
t.Fatalf("Expected stage DONE, but got %s", pr.Stage)
142-
}
143-
validateProgress(t, pr.progress)
144-
validateKeyspaces(t, pr.Keyspaces)
145-
validateHosts(t, pr.Hosts)
146-
validateViews(t, pr.Views, scyllaclient.StatusSuccess)
133+
expectTablesStatus(t, pr.Tables, status)
134+
expectViewsStatus(t, pr.Views, status)
147135
}
148136

149-
func validateProgress(t *testing.T, p progress) {
137+
func expectTablesStatus(t *testing.T, tables []TableProgress, status ProgressStatus) {
150138
t.Helper()
151-
if p.Size != p.Restored {
152-
t.Fatalf("Expected to restore %d, but restored %d", p.Size, p.Restored)
153-
}
154-
if p.Size != p.Downloaded {
155-
t.Fatalf("Expected to download %d, but got %d", p.Size, p.Downloaded)
156-
}
157-
if p.Failed != 0 {
158-
t.Fatalf("Expected failed to be 0, but got: %d", p.Failed)
159-
}
160-
if p.StartedAt == nil {
161-
t.Fatalf("Expected StartedAt != nil, but got nil")
162-
}
163-
if p.CompletedAt == nil {
164-
t.Fatalf("Expected CompletedAt != nil, but got nil")
139+
for _, tp := range tables {
140+
if tp.Status != status {
141+
t.Fatalf("Expected table %q status, but got %q", status, tp.Status)
142+
}
165143
}
166144
}
167145

168-
func validateKeyspaces(t *testing.T, keyspaces []KeyspaceProgress) {
146+
func expectViewsStatus(t *testing.T, views []ViewProgress, status ProgressStatus) {
169147
t.Helper()
170-
if len(keyspaces) == 0 {
171-
t.Fatalf("Expected len(keyspaces) > 0, but got 0")
172-
}
173-
for _, kp := range keyspaces {
174-
validateProgress(t, kp.progress)
175-
if kp.Keyspace == "" {
176-
t.Fatalf("Expected not empty keyspace name, but got ''")
177-
}
178-
if len(kp.Tables) == 0 {
179-
t.Fatalf("Expected %s len(tables) > 0, but got 0", kp.Keyspace)
180-
}
181-
for _, tp := range kp.Tables {
182-
validateProgress(t, tp.progress)
183-
if tp.Table == "" {
184-
t.Fatalf("Expected not empty %s table name, but got ''", kp.Keyspace)
185-
}
186-
if tp.TombstoneGC != modeRepair {
187-
t.Fatalf("Expected tombstone_gc mode of %s.%s to be repair, but got %s", kp.Keyspace, tp.Table, tp.TombstoneGC)
188-
}
148+
for _, vp := range views {
149+
if vp.Status != status {
150+
t.Fatalf("Expected view %q status, but got %q", status, vp.Status)
189151
}
190152
}
191153
}
192154

193-
func validateHosts(t *testing.T, hosts []HostProgress) {
155+
func validateGetProgress(t *testing.T, pr Progress) {
194156
t.Helper()
195-
if len(hosts) != 6 {
196-
t.Fatalf("Expected len(hosts) == 6, but got %d", len(hosts))
157+
validateTablesProgress(t, pr.Tables)
158+
validateViewsProgress(t, pr.Views)
159+
160+
}
161+
162+
func validateTablesProgress(t *testing.T, tables []TableProgress) {
163+
t.Helper()
164+
for _, tp := range tables {
165+
validateProgress(t, tp.progress)
197166
}
198-
for _, hp := range hosts {
199-
if hp.Host == "" {
200-
t.Fatalf("Expected not empty host, but got ''")
201-
}
202-
if hp.ShardCnt == 0 {
203-
t.Fatalf("Expected %s host ShardCound != 0, but got 0", hp.Host)
204-
}
205-
if hp.DownloadedBytes == 0 {
206-
t.Fatalf("Expected not empty %s host DownloadedBytes, but got 0", hp.Host)
207-
}
208-
if hp.DownloadDuration == 0 {
209-
t.Fatalf("Expected not empty %s host DownloadDuration, but got 0", hp.Host)
210-
}
167+
}
168+
169+
func validateViewsProgress(t *testing.T, views []ViewProgress) {
170+
t.Helper()
171+
172+
for _, vp := range views {
173+
validateProgress(t, vp.progress)
211174
}
212175
}
213176

214-
func validateViews(t *testing.T, views []View, expectedBuildStatus scyllaclient.ViewBuildStatus) {
177+
func validateProgress(t *testing.T, p progress) {
215178
t.Helper()
216-
if len(views) == 0 {
217-
t.Fatalf("Expected len(views) > 0, but got 0")
179+
if p.Size != p.Restored {
180+
t.Fatalf("Expected to restore %d, but restored %d", p.Size, p.Restored)
218181
}
219-
for _, v := range views {
220-
if v.Keyspace == "" {
221-
t.Fatalf("Expected not empty view.Keyspace, but got ''")
222-
}
223-
if v.BaseTable == "" {
224-
t.Fatalf("Expected not empty view.BaseTable, but got ''")
225-
}
226-
if v.View == "" {
227-
t.Fatalf("Expected not empty view.View, but got ''")
228-
}
229-
if v.Type == "" {
230-
t.Fatalf("Expected not empty view.Type, but got ''")
231-
}
232-
if v.BuildStatus != expectedBuildStatus {
233-
t.Fatalf("Expected view.BuildStatus '%s', but got '%s'", expectedBuildStatus, v.BuildStatus)
234-
}
182+
if p.StartedAt == nil {
183+
t.Fatalf("Expected StartedAt != nil, but got nil")
184+
}
185+
if p.CompletedAt == nil {
186+
t.Fatalf("Expected CompletedAt != nil, but got nil")
187+
}
188+
if p.Status != ProgressStatusDone {
189+
t.Fatalf("Expected status %q, but got %q", ProgressStatusDone, p.Status)
235190
}
236191
}

0 commit comments

Comments
 (0)