From c1a54756e89b0d872475c5f5c579e355438a2a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Wed, 21 Aug 2024 16:17:39 +0200 Subject: [PATCH] Rename "Close" to "ShutDown" --- relay/client/client_test.go | 20 ++++++++++---------- relay/client/manager_test.go | 16 ++++++++-------- relay/cmd/main.go | 2 +- relay/server/listener/listener.go | 2 +- relay/server/listener/ws/listener.go | 2 +- relay/server/relay.go | 4 ++-- relay/server/server.go | 8 ++++---- relay/test/benchmark_test.go | 2 +- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/relay/client/client_test.go b/relay/client/client_test.go index dc7f70b43..5ac64f23e 100644 --- a/relay/client/client_test.go +++ b/relay/client/client_test.go @@ -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) } diff --git a/relay/client/manager_test.go b/relay/client/manager_test.go index b11e49737..ce94d62fe 100644 --- a/relay/client/manager_test.go +++ b/relay/client/manager_test.go @@ -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) } diff --git a/relay/cmd/main.go b/relay/cmd/main.go index c4fcbc994..239976422 100644 --- a/relay/cmd/main.go +++ b/relay/cmd/main.go @@ -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) } diff --git a/relay/server/listener/listener.go b/relay/server/listener/listener.go index 45167ac1d..535c8bcd9 100644 --- a/relay/server/listener/listener.go +++ b/relay/server/listener/listener.go @@ -7,5 +7,5 @@ import ( type Listener interface { Listen(func(conn net.Conn)) error - Close(ctx context.Context) error + Shutdown(ctx context.Context) error } diff --git a/relay/server/listener/ws/listener.go b/relay/server/listener/ws/listener.go index c429e4545..2034b709a 100644 --- a/relay/server/listener/ws/listener.go +++ b/relay/server/listener/ws/listener.go @@ -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 } diff --git a/relay/server/relay.go b/relay/server/relay.go index 45f52824a..31b7db22c 100644 --- a/relay/server/relay.go +++ b/relay/server/relay.go @@ -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{} diff --git a/relay/server/server.go b/relay/server/server.go index c96e2c25d..0036e2390 100644 --- a/relay/server/server.go +++ b/relay/server/server.go @@ -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 } diff --git a/relay/test/benchmark_test.go b/relay/test/benchmark_test.go index 620902a2a..75560705c 100644 --- a/relay/test/benchmark_test.go +++ b/relay/test/benchmark_test.go @@ -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) }