-
-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exit from processConnResults after all tries (#2621)
* Exit from processConnResults after all tries If all server is unavailable then the server picker never return because we never close the result channel. Count the number of the results and exit when we reached the expected size
- Loading branch information
Showing
2 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestServerPicker_UnavailableServers(t *testing.T) { | ||
sp := ServerPicker{ | ||
TokenStore: nil, | ||
PeerID: "test", | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) | ||
defer cancel() | ||
|
||
go func() { | ||
_, err := sp.PickServer(ctx, []string{"rel://dummy1", "rel://dummy2"}) | ||
if err == nil { | ||
t.Error(err) | ||
} | ||
cancel() | ||
}() | ||
|
||
<-ctx.Done() | ||
if errors.Is(ctx.Err(), context.DeadlineExceeded) { | ||
t.Errorf("PickServer() took too long to complete") | ||
} | ||
} |