Rename "Close" to "ShutDown"

This commit is contained in:
Zoltán Papp 2024-08-21 16:17:39 +02:00
parent a208e7999c
commit c1a54756e8
8 changed files with 28 additions and 28 deletions

View File

@ -47,7 +47,7 @@ func TestClient(t *testing.T) {
}()
defer func() {
err := srv.Close(ctx)
err := srv.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -135,14 +135,14 @@ func TestRegistration(t *testing.T) {
clientAlice := NewClient(ctx, serverURL, hmacTokenStore, "alice")
err = clientAlice.Connect()
if err != nil {
_ = srv.Close(ctx)
_ = srv.Shutdown(ctx)
t.Fatalf("failed to connect to server: %s", err)
}
err = clientAlice.Close()
if err != nil {
t.Errorf("failed to close conn: %s", err)
}
err = srv.Close(ctx)
err = srv.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -202,7 +202,7 @@ func TestEcho(t *testing.T) {
}()
defer func() {
err := srv.Close(ctx)
err := srv.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -292,7 +292,7 @@ func TestBindToUnavailabePeer(t *testing.T) {
defer func() {
log.Infof("closing server")
err := srv.Close(ctx)
err := srv.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -338,7 +338,7 @@ func TestBindReconnect(t *testing.T) {
defer func() {
log.Infof("closing server")
err := srv.Close(ctx)
err := srv.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -429,7 +429,7 @@ func TestCloseConn(t *testing.T) {
defer func() {
log.Infof("closing server")
err := srv.Close(ctx)
err := srv.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -485,7 +485,7 @@ func TestCloseRelayConn(t *testing.T) {
}()
defer func() {
err := srv.Close(ctx)
err := srv.Shutdown(ctx)
if err != nil {
log.Errorf("failed to close server: %s", err)
}
@ -556,7 +556,7 @@ func TestCloseByServer(t *testing.T) {
close(disconnected)
})
err = srv1.Close(ctx)
err = srv1.Shutdown(ctx)
if err != nil {
t.Fatalf("failed to close server: %s", err)
}
@ -612,7 +612,7 @@ func TestCloseByClient(t *testing.T) {
t.Errorf("unexpected opening connection to closed server")
}
err = srv.Close(ctx)
err = srv.Shutdown(ctx)
if err != nil {
t.Fatalf("failed to close server: %s", err)
}

View File

@ -38,7 +38,7 @@ func TestForeignConn(t *testing.T) {
}()
defer func() {
err := srv1.Close(ctx)
err := srv1.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -64,7 +64,7 @@ func TestForeignConn(t *testing.T) {
}()
defer func() {
err := srv2.Close(ctx)
err := srv2.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -150,7 +150,7 @@ func TestForeginConnClose(t *testing.T) {
}()
defer func() {
err := srv1.Close(ctx)
err := srv1.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -176,7 +176,7 @@ func TestForeginConnClose(t *testing.T) {
}()
defer func() {
err := srv2.Close(ctx)
err := srv2.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -227,7 +227,7 @@ func TestForeginAutoClose(t *testing.T) {
defer func() {
t.Logf("closing server 1.")
err := srv1.Close(ctx)
err := srv1.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -255,7 +255,7 @@ func TestForeginAutoClose(t *testing.T) {
}()
defer func() {
t.Logf("closing server 2.")
err := srv2.Close(ctx)
err := srv2.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}
@ -317,7 +317,7 @@ func TestAutoReconnect(t *testing.T) {
}()
defer func() {
err := srv.Close(ctx)
err := srv.Shutdown(ctx)
if err != nil {
log.Errorf("failed to close server: %s", err)
}
@ -381,7 +381,7 @@ func TestNotifierDoubleAdd(t *testing.T) {
}()
defer func() {
err := srv1.Close(ctx)
err := srv1.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}

View File

@ -179,7 +179,7 @@ func execute(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
err = srv.Close(ctx)
err = srv.Shutdown(ctx)
if err != nil {
return fmt.Errorf("failed to close server: %s", err)
}

View File

@ -7,5 +7,5 @@ import (
type Listener interface {
Listen(func(conn net.Conn)) error
Close(ctx context.Context) error
Shutdown(ctx context.Context) error
}

View File

@ -46,7 +46,7 @@ func (l *Listener) Listen(acceptFn func(conn net.Conn)) error {
return err
}
func (l *Listener) Close(ctx context.Context) error {
func (l *Listener) Shutdown(ctx context.Context) error {
if l.server == nil {
return nil
}

View File

@ -101,9 +101,9 @@ func (r *Relay) Accept(conn net.Conn) {
}()
}
// Close closes the relay server
// Shutdown closes the relay server
// It closes the connection with all peers in gracefully and stops accepting new connections.
func (r *Relay) Close(ctx context.Context) {
func (r *Relay) Shutdown(ctx context.Context) {
log.Infof("close connection with all peers")
r.closeMu.Lock()
wg := sync.WaitGroup{}

View File

@ -58,15 +58,15 @@ func (r *Server) Listen(cfg ListenerConfig) error {
return wslErr
}
// Close stops the relay server. If there are active connections, they will be closed gracefully. In case of a timeout,
// Shutdown stops the relay server. If there are active connections, they will be closed gracefully. In case of a context,
// the connections will be forcefully closed.
func (r *Server) Close(ctx context.Context) (err error) {
func (r *Server) Shutdown(ctx context.Context) (err error) {
// stop service new connections
if r.wSListener != nil {
err = r.wSListener.Close(ctx)
err = r.wSListener.Shutdown(ctx)
}
r.relay.Close(ctx)
r.relay.Shutdown(ctx)
return
}

View File

@ -85,7 +85,7 @@ func transfer(t *testing.T, testData []byte, peerPairs int) {
}()
defer func() {
err := srv.Close(ctx)
err := srv.Shutdown(ctx)
if err != nil {
t.Errorf("failed to close server: %s", err)
}