Global discovery should time out (fixes #2389)

This commit is contained in:
Jakob Borg
2015-10-21 14:24:33 +02:00
parent dc1f3503be
commit f241b7e79a
2 changed files with 23 additions and 0 deletions

View File

@@ -79,11 +79,26 @@ func TestGlobalOverHTTP(t *testing.T) {
mux.HandleFunc("/", s.handler)
go http.Serve(list, mux)
// This should succeed
direct, relays, err := testLookup("http://" + list.Addr().String() + "?insecure&noannounce")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !testing.Short() {
// This should time out
_, _, err = testLookup("http://" + list.Addr().String() + "/block?insecure&noannounce")
if err == nil {
t.Fatalf("unexpected nil error, should have been a timeout")
}
}
// This should work again
_, _, err = testLookup("http://" + list.Addr().String() + "?insecure&noannounce")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(direct) != 1 || direct[0] != "tcp://192.0.2.42::22000" {
t.Errorf("incorrect direct list: %+v", direct)
}
@@ -231,6 +246,11 @@ type fakeDiscoveryServer struct {
}
func (s *fakeDiscoveryServer) handler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/block" {
// Never return for requests here
select {}
}
if r.Method == "POST" {
s.announce, _ = ioutil.ReadAll(r.Body)
w.WriteHeader(204)