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 ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
@ -152,7 +153,10 @@ func (s *Server) Start() error {
} }
s.lis = lis s.lis = lis
s.log.Infof("[HTTP] server listening on: %s", lis.Addr().String()) 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. // Stop stop the HTTP server.

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

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

Loading…
Cancel
Save