@@ -261,6 +261,7 @@ func TestCreateStreamCursor(t *testing.T) {
261
261
t .Fatalf ("Expected success, got %s" , describe (err ))
262
262
}
263
263
}
264
+ t .Log ("Completed inserting 10k docs" )
264
265
265
266
const expectedResults int = 10 * 10000
266
267
query := "FOR doc IN cursor_stream_test RETURN doc"
@@ -270,14 +271,10 @@ func TestCreateStreamCursor(t *testing.T) {
270
271
// create a bunch of read-only cursors
271
272
for i := 0 ; i < 10 ; i ++ {
272
273
cursor , err := db .Query (ctx2 , query , nil )
273
- if err == nil {
274
- // Close upon exit of the function
275
- defer cursor .Close ()
276
- }
277
274
if err != nil {
278
- t .Errorf ("Expected success in query %d (%s), got '%s'" , i , query , describe (err ))
279
- continue
275
+ t .Fatalf ("Expected success in query %d (%s), got '%s'" , i , query , describe (err ))
280
276
}
277
+ defer cursor .Close ()
281
278
count := cursor .Count ()
282
279
if count != 0 {
283
280
t .Errorf ("Expected count of 0, got %d in query %d (%s)" , count , i , query )
@@ -294,25 +291,24 @@ func TestCreateStreamCursor(t *testing.T) {
294
291
cursors = append (cursors , cursor )
295
292
}
296
293
294
+ t .Logf ("Created %d cursors" , len (cursors ))
295
+
297
296
// start a write query on the same collection inbetween
298
297
// contrary to normal cursors which are executed right
299
298
// away this will block until all read cursors are resolved
300
299
testReady := make (chan bool )
301
300
go func () {
302
301
query = "FOR doc IN 1..5 LET y = SLEEP(0.01) INSERT {name:'Peter', age:0} INTO cursor_stream_test"
303
302
cursor , err := db .Query (ctx2 , query , nil ) // should not return immediately
304
- if err == nil {
305
- // Close upon exit of the function
306
- defer cursor .Close ()
307
- }
308
303
if err != nil {
309
- t .Errorf ("Expected success in write-query %s, got '%s'" , query , describe (err ))
304
+ t .Fatalf ("Expected success in write-query %s, got '%s'" , query , describe (err ))
310
305
}
306
+ defer cursor .Close ()
311
307
312
308
for cursor .HasMore () {
313
309
var data interface {}
314
310
if _ , err := cursor .ReadDocument (ctx2 , & data ); err != nil {
315
- t .Errorf ("Failed to read document, err: %s" , describe (err ))
311
+ t .Fatalf ("Failed to read document, err: %s" , describe (err ))
316
312
}
317
313
}
318
314
testReady <- true // signal write done
@@ -325,7 +321,7 @@ func TestCreateStreamCursor(t *testing.T) {
325
321
for cursor .HasMore () {
326
322
var user UserDoc
327
323
if _ , err := cursor .ReadDocument (ctx2 , & user ); err != nil {
328
- t .Errorf ("Failed to result document %d: %s" , i , describe (err ))
324
+ t .Fatalf ("Failed to result document %d: %s" , i , describe (err ))
329
325
}
330
326
readCount ++
331
327
}
@@ -335,10 +331,9 @@ func TestCreateStreamCursor(t *testing.T) {
335
331
336
332
writeDone := false
337
333
readDone := false
338
- deadline := time .Now ().Add (time .Second * 30 )
339
334
for {
340
335
select {
341
- case <- time . After ( time . Until ( deadline ) ):
336
+ case <- ctx . Done ( ):
342
337
t .Fatal ("Timeout" )
343
338
case v := <- testReady :
344
339
if v {
0 commit comments