fix http.Server closed

pull/709/head
chenzhihui 4 years ago
parent c089611e5d
commit 4c67fa1235
  1. 6
      transport/http/server.go
  2. 3
      transport/http/server_test.go
  3. 3
      transport/http/service_test.go

@ -2,6 +2,7 @@ package http
import (
"context"
"errors"
"fmt"
"net"
"net/http"
@ -152,7 +153,10 @@ func (s *Server) Start() error {
}
s.lis = lis
s.log.Infof("[HTTP] server listening on: %s", lis.Addr().String())
return s.Serve(lis)
if err := s.Serve(lis); !errors.Is(err, http.ErrServerClosed) {
return err
}
return nil
}
// Stop stop the HTTP server.

@ -3,7 +3,6 @@ package http
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"testing"
@ -38,7 +37,7 @@ func TestServer(t *testing.T) {
testClient(t, srv)
})
if err := srv.Start(); !errors.Is(err, http.ErrServerClosed) {
if err := srv.Start(); err != nil {
t.Fatal(err)
}
}

@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"testing"
@ -61,7 +60,7 @@ func TestService(t *testing.T) {
testServiceClient(t, srv)
})
if err := srv.Start(); !errors.Is(err, http.ErrServerClosed) {
if err := srv.Start(); err != nil {
t.Fatal(err)
}
}

Loading…
Cancel
Save