Files
tasks/common/testing/nettest/rpc_factory_test.go
zeekay 1c76604f15 feat: ZAP transport for internode RPC, replace gRPC for history/matching/worker
- New zaptransport package: factory, client, server, rpcserver
- Internode services (history, matching, worker) use ZAP
- Frontend keeps gRPC for Temporal SDK backward compat (for now)
- luxfi/zap added as dependency
2026-04-09 18:18:31 -07:00

89 lines
2.3 KiB
Go

package nettest_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/hanzoai/tasks/common/testing/nettest"
"google.golang.org/grpc"
)
func TestRPCFactory_GetFrontendGRPCServerOptions(t *testing.T) {
t.Parallel()
rpcFactory := newRPCFactory()
opts, err := rpcFactory.GetFrontendGRPCServerOptions()
require.NoError(t, err)
assert.Empty(t, opts)
}
func TestRPCFactory_GetInternodeGRPCServerOptions(t *testing.T) {
t.Parallel()
rpcFactory := newRPCFactory()
opts, err := rpcFactory.GetInternodeGRPCServerOptions()
require.NoError(t, err)
assert.Empty(t, opts)
}
func TestRPCFactory_CreateHistoryGRPCConnection(t *testing.T) {
t.Parallel()
testDialer(t, "localhost", func(rpcFactory *nettest.RPCFactory) grpc.ClientConnInterface {
return rpcFactory.CreateHistoryGRPCConnection("localhost")
})
}
func TestRPCFactory_CreateMatchingGRPCConnection(t *testing.T) {
t.Parallel()
testDialer(t, "localhost", func(rpcFactory *nettest.RPCFactory) grpc.ClientConnInterface {
return rpcFactory.CreateMatchingGRPCConnection("localhost")
})
}
func TestRPCFactory_CreateLocalFrontendGRPCConnection(t *testing.T) {
t.Parallel()
testDialer(t, ":0", func(rpcFactory *nettest.RPCFactory) grpc.ClientConnInterface {
return rpcFactory.CreateLocalFrontendGRPCConnection()
})
}
func TestRPCFactory_CreateRemoteFrontendGRPCConnection(t *testing.T) {
t.Parallel()
testDialer(t, "localhost", func(rpcFactory *nettest.RPCFactory) grpc.ClientConnInterface {
return rpcFactory.CreateRemoteFrontendGRPCConnection("localhost")
})
}
func testDialer(t *testing.T, target string, dial func(rpcFactory *nettest.RPCFactory) grpc.ClientConnInterface) {
t.Helper()
t.Run("HappyPath", func(t *testing.T) {
t.Parallel()
rpcFactory := newRPCFactory()
errs := make(chan error, 1)
go func() {
_, err := rpcFactory.GetGRPCListener().Accept()
errs <- err
}()
connIface := dial(rpcFactory)
// The nettest factory returns *grpc.ClientConn under the interface.
conn := connIface.(*grpc.ClientConn)
conn.Connect()
require.NoError(t, <-errs)
assert.Equal(t, target, conn.Target())
assert.NoError(t, conn.Close())
})
}
func newRPCFactory(dialOptions ...grpc.DialOption) *nettest.RPCFactory {
return nettest.NewRPCFactory(nettest.NewListener(nettest.NewPipe()), dialOptions...)
}