move to go1.24 (#21114)

This commit is contained in:
Harshavardhana
2025-04-09 07:28:39 -07:00
committed by GitHub
parent a6258668a6
commit 2b34e5b9ae
74 changed files with 434 additions and 458 deletions

View File

@@ -78,7 +78,7 @@ func benchmarkGridRequests(b *testing.B, n int) {
for par := 1; par <= 32; par *= 2 {
b.Run("par="+strconv.Itoa(par*runtime.GOMAXPROCS(0)), func(b *testing.B) {
defer timeout(60 * time.Second)()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(b.Context(), 30*time.Second)
defer cancel()
b.ReportAllocs()
b.SetBytes(int64(len(payload) * 2))
@@ -135,7 +135,7 @@ func benchmarkGridRequests(b *testing.B, n int) {
for par := 1; par <= 32; par *= 2 {
b.Run("par="+strconv.Itoa(par*runtime.GOMAXPROCS(0)), func(b *testing.B) {
defer timeout(60 * time.Second)()
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(b.Context(), 30*time.Second)
defer cancel()
b.ReportAllocs()
b.ResetTimer()
@@ -285,7 +285,7 @@ func benchmarkGridStreamRespOnly(b *testing.B, n int) {
if conn == nil {
b.Fatal("No connection")
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(b.Context(), 30*time.Second)
// Send the payload.
t := time.Now()
st, err := conn.NewStream(ctx, handlerTest, payload)
@@ -396,7 +396,7 @@ func benchmarkGridStreamReqOnly(b *testing.B, n int) {
if conn == nil {
b.Fatal("No connection")
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(b.Context(), 30*time.Second)
// Send the payload.
t := time.Now()
st, err := conn.NewStream(ctx, handlerTest, payload)
@@ -512,7 +512,7 @@ func benchmarkGridStreamTwoway(b *testing.B, n int) {
if conn == nil {
b.Fatal("No connection")
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cancel := context.WithTimeout(b.Context(), 30*time.Second)
// Send the payload.
t := time.Now()
st, err := conn.NewStream(ctx, handlerTest, payload)

View File

@@ -51,7 +51,7 @@ func TestDisconnect(t *testing.T) {
// We fake a local and remote server.
localHost := hosts[0]
remoteHost := hosts[1]
local, err := NewManager(context.Background(), ManagerOptions{
local, err := NewManager(t.Context(), ManagerOptions{
Dialer: ConnectWS(dialer.DialContext,
dummyNewToken,
nil),
@@ -75,7 +75,7 @@ func TestDisconnect(t *testing.T) {
return nil, &err
}))
remote, err := NewManager(context.Background(), ManagerOptions{
remote, err := NewManager(t.Context(), ManagerOptions{
Dialer: ConnectWS(dialer.DialContext,
dummyNewToken,
nil),
@@ -131,14 +131,14 @@ func TestDisconnect(t *testing.T) {
// local to remote
remoteConn := local.Connection(remoteHost)
errFatal(remoteConn.WaitForConnect(context.Background()))
errFatal(remoteConn.WaitForConnect(t.Context()))
const testPayload = "Hello Grid World!"
gotResp := make(chan struct{})
go func() {
start := time.Now()
t.Log("Roundtrip: sending request")
resp, err := remoteConn.Request(context.Background(), handlerTest, []byte(testPayload))
resp, err := remoteConn.Request(t.Context(), handlerTest, []byte(testPayload))
t.Log("Roundtrip:", time.Since(start), resp, err)
gotResp <- struct{}{}
}()
@@ -148,9 +148,9 @@ func TestDisconnect(t *testing.T) {
<-gotResp
// Must reconnect
errFatal(remoteConn.WaitForConnect(context.Background()))
errFatal(remoteConn.WaitForConnect(t.Context()))
stream, err := remoteConn.NewStream(context.Background(), handlerTest2, []byte(testPayload))
stream, err := remoteConn.NewStream(t.Context(), handlerTest2, []byte(testPayload))
errFatal(err)
go func() {
for resp := range stream.responses {
@@ -162,7 +162,7 @@ func TestDisconnect(t *testing.T) {
<-gotCall
remote.debugMsg(debugKillOutbound)
local.debugMsg(debugKillOutbound)
errFatal(remoteConn.WaitForConnect(context.Background()))
errFatal(remoteConn.WaitForConnect(t.Context()))
<-gotResp
// Killing should cancel the context on the request.

View File

@@ -74,14 +74,14 @@ func TestSingleRoundtrip(t *testing.T) {
// local to remote
remoteConn := local.Connection(remoteHost)
remoteConn.WaitForConnect(context.Background())
remoteConn.WaitForConnect(t.Context())
defer testlogger.T.SetErrorTB(t)()
t.Run("localToRemote", func(t *testing.T) {
const testPayload = "Hello Grid World!"
start := time.Now()
resp, err := remoteConn.Request(context.Background(), handlerTest, []byte(testPayload))
resp, err := remoteConn.Request(t.Context(), handlerTest, []byte(testPayload))
errFatal(err)
if string(resp) != testPayload {
t.Errorf("want %q, got %q", testPayload, string(resp))
@@ -92,7 +92,7 @@ func TestSingleRoundtrip(t *testing.T) {
t.Run("localToRemoteErr", func(t *testing.T) {
const testPayload = "Hello Grid World!"
start := time.Now()
resp, err := remoteConn.Request(context.Background(), handlerTest2, []byte(testPayload))
resp, err := remoteConn.Request(t.Context(), handlerTest2, []byte(testPayload))
t.Log("Roundtrip:", time.Since(start))
if len(resp) != 0 {
t.Errorf("want nil, got %q", string(resp))
@@ -107,7 +107,7 @@ func TestSingleRoundtrip(t *testing.T) {
testPayload := bytes.Repeat([]byte("?"), 1<<20)
start := time.Now()
resp, err := remoteConn.Request(context.Background(), handlerTest, testPayload)
resp, err := remoteConn.Request(t.Context(), handlerTest, testPayload)
errFatal(err)
if string(resp) != string(testPayload) {
t.Errorf("want %q, got %q", testPayload, string(resp))
@@ -119,7 +119,7 @@ func TestSingleRoundtrip(t *testing.T) {
testPayload := bytes.Repeat([]byte("!"), 1<<10)
start := time.Now()
resp, err := remoteConn.Request(context.Background(), handlerTest2, testPayload)
resp, err := remoteConn.Request(t.Context(), handlerTest2, testPayload)
if len(resp) != 0 {
t.Errorf("want nil, got %q", string(resp))
}
@@ -159,19 +159,19 @@ func TestSingleRoundtripNotReady(t *testing.T) {
// local to remote
remoteConn := local.Connection(remoteHost)
remoteConn.WaitForConnect(context.Background())
remoteConn.WaitForConnect(t.Context())
defer testlogger.T.SetErrorTB(t)()
t.Run("localToRemote", func(t *testing.T) {
const testPayload = "Hello Grid World!"
// Single requests should have remote errors.
_, err := remoteConn.Request(context.Background(), handlerTest, []byte(testPayload))
_, err := remoteConn.Request(t.Context(), handlerTest, []byte(testPayload))
if _, ok := err.(*RemoteErr); !ok {
t.Fatalf("Unexpected error: %v, %T", err, err)
}
// Streams should not be able to set up until registered.
// Thus, the error is a local error.
_, err = remoteConn.NewStream(context.Background(), handlerTest, []byte(testPayload))
_, err = remoteConn.NewStream(t.Context(), handlerTest, []byte(testPayload))
if !errors.Is(err, ErrUnknownHandler) {
t.Fatalf("Unexpected error: %v, %T", err, err)
}
@@ -226,7 +226,7 @@ func TestSingleRoundtripGenerics(t *testing.T) {
start := time.Now()
req := testRequest{Num: 1, String: testPayload}
resp, err := h1.Call(context.Background(), remoteConn, &req)
resp, err := h1.Call(t.Context(), remoteConn, &req)
errFatal(err)
if resp.OrgString != testPayload {
t.Errorf("want %q, got %q", testPayload, resp.OrgString)
@@ -235,7 +235,7 @@ func TestSingleRoundtripGenerics(t *testing.T) {
h1.PutResponse(resp)
start = time.Now()
resp, err = h2.Call(context.Background(), remoteConn, &testRequest{Num: 1, String: testPayload})
resp, err = h2.Call(t.Context(), remoteConn, &testRequest{Num: 1, String: testPayload})
t.Log("Roundtrip:", time.Since(start))
if err != RemoteErr(testPayload) {
t.Errorf("want error %v(%T), got %v(%T)", RemoteErr(testPayload), RemoteErr(testPayload), err, err)
@@ -290,7 +290,7 @@ func TestSingleRoundtripGenericsRecycle(t *testing.T) {
start := time.Now()
req := NewMSSWith(map[string]string{"test": testPayload})
resp, err := h1.Call(context.Background(), remoteConn, req)
resp, err := h1.Call(t.Context(), remoteConn, req)
errFatal(err)
if resp.Get("test") != testPayload {
t.Errorf("want %q, got %q", testPayload, resp.Get("test"))
@@ -299,7 +299,7 @@ func TestSingleRoundtripGenericsRecycle(t *testing.T) {
h1.PutResponse(resp)
start = time.Now()
resp, err = h2.Call(context.Background(), remoteConn, NewMSSWith(map[string]string{"err": testPayload}))
resp, err = h2.Call(t.Context(), remoteConn, NewMSSWith(map[string]string{"err": testPayload}))
t.Log("Roundtrip:", time.Since(start))
if err != RemoteErr(testPayload) {
t.Errorf("want error %v(%T), got %v(%T)", RemoteErr(testPayload), RemoteErr(testPayload), err, err)
@@ -479,7 +479,7 @@ func testStreamRoundtrip(t *testing.T, local, remote *Manager) {
const testPayload = "Hello Grid World!"
start := time.Now()
stream, err := remoteConn.NewStream(context.Background(), handlerTest, []byte(testPayload))
stream, err := remoteConn.NewStream(t.Context(), handlerTest, []byte(testPayload))
errFatal(err)
var n int
stream.Requests <- []byte(strconv.Itoa(n))
@@ -544,7 +544,7 @@ func testStreamCancel(t *testing.T, local, remote *Manager) {
remoteConn := local.Connection(remoteHost)
const testPayload = "Hello Grid World!"
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(t.Context())
st, err := remoteConn.NewStream(ctx, handler, []byte(testPayload))
errFatal(err)
clientCanceled := make(chan time.Time, 1)
@@ -659,7 +659,7 @@ func testStreamDeadline(t *testing.T, local, remote *Manager) {
remoteConn := local.Connection(remoteHost)
const testPayload = "Hello Grid World!"
ctx, cancel := context.WithTimeout(context.Background(), wantDL)
ctx, cancel := context.WithTimeout(t.Context(), wantDL)
defer cancel()
st, err := remoteConn.NewStream(ctx, handler, []byte(testPayload))
errFatal(err)
@@ -735,7 +735,7 @@ func testServerOutCongestion(t *testing.T, local, remote *Manager) {
remoteConn := local.Connection(remoteHost)
const testPayload = "Hello Grid World!"
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(t.Context(), time.Minute)
defer cancel()
st, err := remoteConn.NewStream(ctx, handlerTest, []byte(testPayload))
errFatal(err)
@@ -813,7 +813,7 @@ func testServerInCongestion(t *testing.T, local, remote *Manager) {
remoteConn := local.Connection(remoteHost)
const testPayload = "Hello Grid World!"
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(t.Context(), time.Minute)
defer cancel()
st, err := remoteConn.NewStream(ctx, handlerTest, []byte(testPayload))
errFatal(err)
@@ -893,7 +893,7 @@ func testGenericsStreamRoundtrip(t *testing.T, local, remote *Manager) {
const testPayload = "Hello Grid World!"
start := time.Now()
stream, err := handler.Call(context.Background(), remoteConn, &testRequest{Num: 1, String: testPayload})
stream, err := handler.Call(t.Context(), remoteConn, &testRequest{Num: 1, String: testPayload})
errFatal(err)
go func() {
defer close(stream.Requests)
@@ -970,7 +970,7 @@ func testGenericsStreamRoundtripSubroute(t *testing.T, local, remote *Manager) {
remoteSub := remoteConn.Subroute(strings.Join([]string{"subroute", "1"}, "/"))
start := time.Now()
stream, err := handler.Call(context.Background(), remoteSub, &testRequest{Num: 1, String: testPayload})
stream, err := handler.Call(t.Context(), remoteSub, &testRequest{Num: 1, String: testPayload})
errFatal(err)
go func() {
defer close(stream.Requests)
@@ -1043,7 +1043,7 @@ func testServerStreamResponseBlocked(t *testing.T, local, remote *Manager) {
remoteConn := local.Connection(remoteHost)
const testPayload = "Hello Grid World!"
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second)
st, err := remoteConn.NewStream(ctx, handlerTest, []byte(testPayload))
errFatal(err)
@@ -1125,7 +1125,7 @@ func testServerStreamNoPing(t *testing.T, local, remote *Manager, inCap int) {
remoteConn.debugMsg(debugSetClientPingDuration, 100*time.Millisecond)
defer remoteConn.debugMsg(debugSetClientPingDuration, clientPingInterval)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(t.Context(), time.Minute)
defer cancel()
st, err := remoteConn.NewStream(ctx, handlerTest, []byte(testPayload))
errFatal(err)
@@ -1198,7 +1198,7 @@ func testServerStreamPingRunning(t *testing.T, local, remote *Manager, inCap int
remoteConn.debugMsg(debugSetClientPingDuration, 100*time.Millisecond)
defer remoteConn.debugMsg(debugSetClientPingDuration, clientPingInterval)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
ctx, cancel := context.WithTimeout(t.Context(), time.Minute)
defer cancel()
st, err := remoteConn.NewStream(ctx, handlerTest, []byte(testPayload))
errFatal(err)