File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -390,7 +390,9 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
390
390
srs := make ([]* Entry , 0 )
391
391
ctx , cancel := context .WithCancel (context .Background ())
392
392
defer cancel ()
393
- for sr := range l .SearchWithChannel (ctx , searchRequest ) {
393
+ ch := l .SearchWithChannel (ctx , searchRequest )
394
+ for i := 0 ; i < 10 ; i ++ {
395
+ sr := <- ch
394
396
if sr .Error != nil {
395
397
t .Fatal (err )
396
398
}
@@ -399,10 +401,8 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
399
401
cancel ()
400
402
}
401
403
}
402
- if len (srs ) > cancelNum + 2 {
403
- // The cancel process is asynchronous,
404
- // so a few entries after it canceled might be received
405
- t .Errorf ("Got entries %d, expected less than %d" , len (srs ), cancelNum + 2 )
404
+ if len (srs ) != cancelNum {
405
+ t .Errorf ("Got entries %d, expected %d" , len (srs ), cancelNum )
406
406
}
407
407
t .Logf ("TestSearchWithChannel: %s -> num of entries = %d" , searchRequest .Filter , len (srs ))
408
408
}
Original file line number Diff line number Diff line change @@ -390,7 +390,9 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
390
390
srs := make ([]* Entry , 0 )
391
391
ctx , cancel := context .WithCancel (context .Background ())
392
392
defer cancel ()
393
- for sr := range l .SearchWithChannel (ctx , searchRequest ) {
393
+ ch := l .SearchWithChannel (ctx , searchRequest )
394
+ for i := 0 ; i < 10 ; i ++ {
395
+ sr := <- ch
394
396
if sr .Error != nil {
395
397
t .Fatal (err )
396
398
}
@@ -399,10 +401,8 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
399
401
cancel ()
400
402
}
401
403
}
402
- if len (srs ) > cancelNum + 2 {
403
- // The cancel process is asynchronous,
404
- // so a few entries after it canceled might be received
405
- t .Errorf ("Got entries %d, expected less than %d" , len (srs ), cancelNum + 2 )
404
+ if len (srs ) != cancelNum {
405
+ t .Errorf ("Got entries %d, expected %d" , len (srs ), cancelNum )
406
406
}
407
407
t .Logf ("TestSearchWithChannel: %s -> num of entries = %d" , searchRequest .Filter , len (srs ))
408
408
}
You can’t perform that action at this time.
0 commit comments