@@ -10,12 +10,10 @@ import (
10
10
"os"
11
11
"testing"
12
12
13
- "github.com/scylladb/scylla-manager/v3/pkg/scyllaclient"
14
13
"github.com/scylladb/scylla-manager/v3/pkg/service/backup/backupspec"
15
14
"github.com/scylladb/scylla-manager/v3/pkg/testutils"
16
15
"github.com/scylladb/scylla-manager/v3/pkg/testutils/db"
17
16
"github.com/scylladb/scylla-manager/v3/pkg/testutils/testconfig"
18
- "github.com/scylladb/scylla-manager/v3/pkg/util/timeutc"
19
17
"github.com/scylladb/scylla-manager/v3/pkg/util/uuid"
20
18
)
21
19
@@ -65,172 +63,129 @@ func TestGetProgressIntegration(t *testing.T) {
65
63
if err != nil {
66
64
t .Fatalf ("Unexpected err, prepareHostWorkload: %v" , err )
67
65
}
68
-
69
- testutils .Print ("ALTER_TGC Stage" )
70
- err = w .setTombstoneGCModeRepair (context .Background (), workload )
66
+ pr , err := w .getProgress (context .Background ())
71
67
if err != nil {
72
- t .Fatalf ("Unexpected err, setTombstoneGCModeRepair : %v" , err )
68
+ t .Fatalf ("Unexpected err, getProgress : %v" , err )
73
69
}
70
+ if ! progressIsEmpty (pr ) {
71
+ t .Fatalf ("Expected empty progress, but got: %v" , pr )
72
+ }
73
+
74
+ w .initProgress (context .Background (), workload )
74
75
75
- pr , err : = w .getProgress (context .Background (), target )
76
+ pr , err = w .getProgress (context .Background ())
76
77
if err != nil {
77
78
t .Fatalf ("Unexpected err, getProgress: %v" , err )
78
79
}
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" )
81
82
}
82
- validateKeyspaces (t , pr . Keyspaces )
83
+ expectProgressStatus (t , pr , ProgressStatusNotStarted )
83
84
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 )
86
87
if err != nil {
87
- t .Fatalf ("Unexpected err, dropViews : %v" , err )
88
+ t .Fatalf ("Unexpected err, setTombstoneGCModeRepair : %v" , err )
88
89
}
89
90
90
- pr , err = w .getProgress (context .Background (), target )
91
+ testutils .Print ("DROP_VIEWS Stage" )
92
+ views , err := w .dropViews (context .Background (), workload )
91
93
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 )
96
95
}
97
- validateViews (t , pr .Views , "" )
98
96
99
97
testutils .Print ("DATA Stage" )
100
98
if err := w .restoreTables (context .Background (), workload , target .Keyspace ); err != nil {
101
99
t .Fatalf ("Unexpected err, restoreTables: %v" , err )
102
100
}
103
- pr , err = w .getProgress (context .Background (), target )
101
+
102
+ pr , err = w .getProgress (context .Background ())
104
103
if err != nil {
105
104
t .Fatalf ("Unexpected err, getProgress: %v" , err )
106
105
}
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" )
109
108
}
110
- validateKeyspaces (t , pr .Keyspaces )
111
- validateHosts (t , pr .Hosts )
109
+ expectTablesStatus (t , pr .Tables , ProgressStatusDone )
110
+ expectViewsStatus (t , pr .Views , ProgressStatusNotStarted )
112
111
113
112
testutils .Print ("RECREATE_VIEWS Stage" )
114
113
if err := w .reCreateViews (context .Background (), views ); err != nil {
115
114
t .Fatalf ("Unexpected err, reCreateViews: %v" , err )
116
115
}
117
- pr , err = w .getProgress (context .Background (), target )
116
+
117
+ pr , err = w .getProgress (context .Background ())
118
118
if err != nil {
119
119
t .Fatalf ("Unexpected err, getProgress: %v" , err )
120
120
}
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" )
123
123
}
124
- validateViews (t , pr .Views , scyllaclient .StatusSuccess )
124
+ expectProgressStatus (t , pr , ProgressStatusDone )
125
+ }
125
126
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
133
129
}
134
130
135
- func validateGetProgress (t * testing.T , pr Progress , tag string ) {
131
+ func expectProgressStatus (t * testing.T , pr Progress , status ProgressStatus ) {
136
132
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 )
147
135
}
148
136
149
- func validateProgress (t * testing.T , p progress ) {
137
+ func expectTablesStatus (t * testing.T , tables [] TableProgress , status ProgressStatus ) {
150
138
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
+ }
165
143
}
166
144
}
167
145
168
- func validateKeyspaces (t * testing.T , keyspaces []KeyspaceProgress ) {
146
+ func expectViewsStatus (t * testing.T , views []ViewProgress , status ProgressStatus ) {
169
147
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 )
189
151
}
190
152
}
191
153
}
192
154
193
- func validateHosts (t * testing.T , hosts [] HostProgress ) {
155
+ func validateGetProgress (t * testing.T , pr Progress ) {
194
156
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 )
197
166
}
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 )
211
174
}
212
175
}
213
176
214
- func validateViews (t * testing.T , views [] View , expectedBuildStatus scyllaclient. ViewBuildStatus ) {
177
+ func validateProgress (t * testing.T , p progress ) {
215
178
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 )
218
181
}
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 )
235
190
}
236
191
}
0 commit comments