Skip to content

Commit 1131fd5

Browse files
committed
refactor: fix to check proper test results go-ldap#319
1 parent 81ab75d commit 1131fd5

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

ldap_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,9 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
390390
srs := make([]*Entry, 0)
391391
ctx, cancel := context.WithCancel(context.Background())
392392
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
394396
if sr.Error != nil {
395397
t.Fatal(err)
396398
}
@@ -399,10 +401,8 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
399401
cancel()
400402
}
401403
}
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)
406406
}
407407
t.Logf("TestSearchWithChannel: %s -> num of entries = %d", searchRequest.Filter, len(srs))
408408
}

v3/ldap_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,9 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
390390
srs := make([]*Entry, 0)
391391
ctx, cancel := context.WithCancel(context.Background())
392392
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
394396
if sr.Error != nil {
395397
t.Fatal(err)
396398
}
@@ -399,10 +401,8 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
399401
cancel()
400402
}
401403
}
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)
406406
}
407407
t.Logf("TestSearchWithChannel: %s -> num of entries = %d", searchRequest.Filter, len(srs))
408408
}

0 commit comments

Comments
 (0)