test: grpc add timeout

pull/458/head
Gordon 2 years ago
parent cd464b42dd
commit 8ca51908f0

@ -2,8 +2,6 @@ package api
import ( import (
"context" "context"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw"
@ -18,7 +16,7 @@ import (
) )
func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.UniversalClient) *gin.Engine { func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.UniversalClient) *gin.Engine {
discov.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithTimeout(time.Second*3)) // 默认RPC中间件 discov.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) // 默认RPC中间件
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
//f, _ := os.Create("../logs/api.log") //f, _ := os.Create("../logs/api.log")
//gin.DefaultWriter = io.MultiWriter(f) //gin.DefaultWriter = io.MultiWriter(f)

@ -3,6 +3,7 @@ package rpcclient
import ( import (
"context" "context"
"strings" "strings"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
@ -21,7 +22,8 @@ type User struct {
} }
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User { func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName) ctx, _ := context.WithTimeout(context.Background(), time.Second*3)
conn, err := discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
if err != nil { if err != nil {
panic(err) panic(err)
} }

Loading…
Cancel
Save