@@ -170,7 +170,7 @@ func run(cmd *cobra.Command, args []string) {
170
170
if verbose {
171
171
fmt .Println (stmt )
172
172
}
173
- if err := session .Mutate (stmt ); err != nil {
173
+ if err := session .Mutate (context . Background (), stmt ); err != nil {
174
174
fmt .Printf ("%v" , err )
175
175
return
176
176
}
@@ -180,7 +180,7 @@ func run(cmd *cobra.Command, args []string) {
180
180
if verbose {
181
181
fmt .Println (stmt )
182
182
}
183
- if err := session .Mutate (stmt ); err != nil {
183
+ if err := session .Mutate (context . Background (), stmt ); err != nil {
184
184
fmt .Printf ("%v" , err )
185
185
return
186
186
}
@@ -229,37 +229,39 @@ func runJob(f testJob, schema *gemini.Schema, s *gemini.Session, mode string, ou
229
229
for {
230
230
select {
231
231
case <- timer .C :
232
+ cancelWorkers ()
233
+ testRes = drain (c , testRes )
232
234
testRes .PrintResult (out )
233
235
fmt .Println ("Test run completed. Exiting." )
234
- cancelWorkers ()
235
236
return
236
237
case <- reporterCtx .Done ():
237
- testRes .PrintResult (out )
238
238
return
239
239
case res := <- c :
240
240
testRes = res .Merge (& testRes )
241
241
if sp != nil {
242
242
sp .Suffix = fmt .Sprintf (" Running Gemini... %v" , testRes )
243
243
}
244
244
if testRes .ReadErrors > 0 {
245
- testRes .PrintResult (out )
246
- fmt .Println (testRes .Errors )
247
245
if failFast {
248
246
fmt .Println ("Error in data validation. Exiting." )
249
247
cancelWorkers ()
248
+ testRes = drain (c , testRes )
249
+ testRes .PrintResult (out )
250
250
return
251
251
}
252
+ testRes .PrintResult (out )
252
253
}
253
254
}
254
255
}
255
256
}(duration )
256
257
257
258
workers .Wait ()
259
+ close (c )
258
260
cancelReporter ()
259
261
reporter .Wait ()
260
262
}
261
263
262
- func mutationJob (schema * gemini.Schema , table gemini.Table , s * gemini.Session , p gemini.PartitionRange , testStatus * Status , out * os.File ) {
264
+ func mutationJob (ctx context. Context , schema * gemini.Schema , table gemini.Table , s * gemini.Session , p gemini.PartitionRange , testStatus * Status , out * os.File ) {
263
265
mutateStmt , err := schema .GenMutateStmt (table , & p )
264
266
if err != nil {
265
267
fmt .Printf ("Failed! Mutation statement generation failed: '%v'\n " , err )
@@ -271,7 +273,7 @@ func mutationJob(schema *gemini.Schema, table gemini.Table, s *gemini.Session, p
271
273
if verbose {
272
274
fmt .Println (mutateStmt .PrettyCQL ())
273
275
}
274
- if err := s .Mutate (mutateQuery , mutateValues ... ); err != nil {
276
+ if err := s .Mutate (ctx , mutateQuery , mutateValues ... ); err != nil {
275
277
e := gemini.JobError {
276
278
Timestamp : time .Now (),
277
279
Message : "Mutation failed: " + err .Error (),
@@ -284,14 +286,14 @@ func mutationJob(schema *gemini.Schema, table gemini.Table, s *gemini.Session, p
284
286
}
285
287
}
286
288
287
- func validationJob (schema * gemini.Schema , table gemini.Table , s * gemini.Session , p gemini.PartitionRange , testStatus * Status , out * os.File ) {
289
+ func validationJob (ctx context. Context , schema * gemini.Schema , table gemini.Table , s * gemini.Session , p gemini.PartitionRange , testStatus * Status , out * os.File ) {
288
290
checkStmt := schema .GenCheckStmt (table , & p )
289
291
checkQuery := checkStmt .Query
290
292
checkValues := checkStmt .Values ()
291
293
if verbose {
292
294
fmt .Println (checkStmt .PrettyCQL ())
293
295
}
294
- if err := s .Check (table , checkQuery , checkValues ... ); err != nil {
296
+ if err := s .Check (ctx , table , checkQuery , checkValues ... ); err != nil {
295
297
// De-duplication needed?
296
298
e := gemini.JobError {
297
299
Timestamp : time .Now (),
@@ -318,23 +320,23 @@ func Job(ctx context.Context, wg *sync.WaitGroup, schema *gemini.Schema, table g
318
320
}
319
321
switch mode {
320
322
case writeMode :
321
- mutationJob (schema , table , s , p , & testStatus , out )
323
+ mutationJob (ctx , schema , table , s , p , & testStatus , out )
322
324
case readMode :
323
- validationJob (schema , table , s , p , & testStatus , out )
325
+ validationJob (ctx , schema , table , s , p , & testStatus , out )
324
326
default :
325
327
ind := p .Rand .Intn (100000 ) % 2
326
328
if ind == 0 {
327
- mutationJob (schema , table , s , p , & testStatus , out )
329
+ mutationJob (ctx , schema , table , s , p , & testStatus , out )
328
330
} else {
329
- validationJob (schema , table , s , p , & testStatus , out )
331
+ validationJob (ctx , schema , table , s , p , & testStatus , out )
330
332
}
331
333
}
332
334
333
335
if i % 1000 == 0 {
334
336
c <- testStatus
335
337
testStatus = Status {}
336
338
}
337
- if failFast && testStatus .ReadErrors > 0 {
339
+ if failFast && ( testStatus .ReadErrors > 0 || testStatus . WriteErrors > 0 ) {
338
340
break
339
341
}
340
342
i ++
@@ -390,3 +392,10 @@ func printSetup() error {
390
392
tw .Flush ()
391
393
return nil
392
394
}
395
+
396
+ func drain (ch chan Status , testRes Status ) Status {
397
+ for res := range ch {
398
+ testRes = res .Merge (& testRes )
399
+ }
400
+ return testRes
401
+ }
0 commit comments