修复代理与日志链路的可靠性问题
This commit is contained in:
+7
-8
@@ -7,7 +7,6 @@ import (
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -49,13 +48,13 @@ func TestRunRegistersSignalsBeforeStartingResources(t *testing.T) {
|
||||
}
|
||||
name := owner.Name + "." + selector.Sel.Name
|
||||
switch name {
|
||||
case "signal.Notify", "db.NewPool", "queue.Start", "srv.ListenAndServe":
|
||||
case "signal.NotifyContext", "db.NewPool", "queue.Start", "srv.ListenAndServe":
|
||||
positions[name] = call.Pos()
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
notifyPos, ok := positions["signal.Notify"]
|
||||
notifyPos, ok := positions["signal.NotifyContext"]
|
||||
if !ok {
|
||||
t.Fatal("run does not register for shutdown signals")
|
||||
}
|
||||
@@ -65,7 +64,7 @@ func TestRunRegistersSignalsBeforeStartingResources(t *testing.T) {
|
||||
t.Fatalf("run does not call %s", start)
|
||||
}
|
||||
if notifyPos >= startPos {
|
||||
t.Errorf("signal.Notify at line %d must precede %s at line %d",
|
||||
t.Errorf("signal.NotifyContext at line %d must precede %s at line %d",
|
||||
fset.Position(notifyPos).Line, start, fset.Position(startPos).Line)
|
||||
}
|
||||
}
|
||||
@@ -76,7 +75,7 @@ func TestWaitForShutdownReturnsListenerError(t *testing.T) {
|
||||
serverErr := make(chan error, 1)
|
||||
serverErr <- listenErr
|
||||
|
||||
err := waitForShutdown(make(chan os.Signal), serverErr)
|
||||
err := waitForShutdown(make(chan struct{}), serverErr)
|
||||
if !errors.Is(err, listenErr) || !strings.Contains(err.Error(), "server") {
|
||||
t.Fatalf("waitForShutdown() error = %v, want wrapped listener error", err)
|
||||
}
|
||||
@@ -84,8 +83,8 @@ func TestWaitForShutdownReturnsListenerError(t *testing.T) {
|
||||
|
||||
func TestWaitForShutdownAcceptsSignalAndServerClosed(t *testing.T) {
|
||||
t.Run("signal", func(t *testing.T) {
|
||||
stop := make(chan os.Signal, 1)
|
||||
stop <- os.Interrupt
|
||||
stop := make(chan struct{})
|
||||
close(stop)
|
||||
if err := waitForShutdown(stop, make(chan error)); err != nil {
|
||||
t.Fatalf("waitForShutdown() error = %v, want nil", err)
|
||||
}
|
||||
@@ -94,7 +93,7 @@ func TestWaitForShutdownAcceptsSignalAndServerClosed(t *testing.T) {
|
||||
t.Run("server closed", func(t *testing.T) {
|
||||
serverErr := make(chan error, 1)
|
||||
serverErr <- http.ErrServerClosed
|
||||
if err := waitForShutdown(make(chan os.Signal), serverErr); err != nil {
|
||||
if err := waitForShutdown(make(chan struct{}), serverErr); err != nil {
|
||||
t.Fatalf("waitForShutdown() error = %v, want nil", err)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user