Skip to content

Commit

Permalink
refactor: fix to check proper test results go-ldap#319
Browse files Browse the repository at this point in the history
  • Loading branch information
t2y committed Jun 4, 2023
1 parent 81ab75d commit 1131fd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
srs := make([]*Entry, 0)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
for sr := range l.SearchWithChannel(ctx, searchRequest) {
ch := l.SearchWithChannel(ctx, searchRequest)
for i := 0; i < 10; i++ {
sr := <-ch
if sr.Error != nil {
t.Fatal(err)
}
Expand All @@ -399,10 +401,8 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
cancel()
}
}
if len(srs) > cancelNum+2 {
// The cancel process is asynchronous,
// so a few entries after it canceled might be received
t.Errorf("Got entries %d, expected less than %d", len(srs), cancelNum+2)
if len(srs) != cancelNum {
t.Errorf("Got entries %d, expected %d", len(srs), cancelNum)
}
t.Logf("TestSearchWithChannel: %s -> num of entries = %d", searchRequest.Filter, len(srs))
}
10 changes: 5 additions & 5 deletions v3/ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,9 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
srs := make([]*Entry, 0)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
for sr := range l.SearchWithChannel(ctx, searchRequest) {
ch := l.SearchWithChannel(ctx, searchRequest)
for i := 0; i < 10; i++ {
sr := <-ch
if sr.Error != nil {
t.Fatal(err)
}
Expand All @@ -399,10 +401,8 @@ func TestSearchWithChannelAndCancel(t *testing.T) {
cancel()
}
}
if len(srs) > cancelNum+2 {
// The cancel process is asynchronous,
// so a few entries after it canceled might be received
t.Errorf("Got entries %d, expected less than %d", len(srs), cancelNum+2)
if len(srs) != cancelNum {
t.Errorf("Got entries %d, expected %d", len(srs), cancelNum)
}
t.Logf("TestSearchWithChannel: %s -> num of entries = %d", searchRequest.Filter, len(srs))
}

0 comments on commit 1131fd5

Please sign in to comment.