Skip to content

Commit e0195bc

Browse files
committed
update
1 parent 556d045 commit e0195bc

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

internal/gateway/gateway.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ import (
3232
)
3333

3434
const (
35-
httpRequestPrefix = "/gateway"
36-
xceVanusEventbus = "xvanuseventbus"
35+
httpRequestPrefix = "/gateway"
36+
xceVanusEventbus = "xvanuseventbus"
37+
ctrlProxyPortShift = 2
3738
)
3839

3940
var (
@@ -60,7 +61,7 @@ type ceGateway struct {
6061
func NewGateway(config Config) *ceGateway {
6162
return &ceGateway{
6263
config: config,
63-
cp: newCtrlProxy(config.Port+2, allowCtrlProxyList, config.ControllerAddr),
64+
cp: newCtrlProxy(config.Port+ctrlProxyPortShift, allowCtrlProxyList, config.ControllerAddr),
6465
}
6566
}
6667

internal/gateway/grpc_proxy.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,8 @@ func (cp *ctrlProxy) start(ctx context.Context) error {
6868
}()
6969

7070
go func() {
71-
for {
72-
select {
73-
case <-ctx.Done():
74-
grpcServer.GracefulStop()
75-
}
76-
}
71+
<-ctx.Done()
72+
grpcServer.GracefulStop()
7773
}()
7874
go cp.updateLeader(ctx)
7975
return nil
@@ -89,7 +85,7 @@ func (cp *ctrlProxy) director(ctx context.Context, fullMethodName string) (conte
8985

9086
_, exist := cp.allowProxyMethod[fullMethodName]
9187
if !exist {
92-
log.Warning(nil, "invalid access", map[string]interface{}{
88+
log.Warning(ctx, "invalid access", map[string]interface{}{
9389
"method": fullMethodName,
9490
})
9591
return outCtx, nil, status.Errorf(codes.Unimplemented, "Unknown method")
@@ -182,10 +178,11 @@ func createGRPCConn(ctx context.Context, addr string) *grpc.ClientConn {
182178
ctx, cancel := context.WithCancel(ctx)
183179
timeout := false
184180
go func() {
185-
ticker := time.Tick(time.Second)
181+
ticker := time.NewTicker(time.Second)
182+
defer ticker.Stop()
186183
select {
187184
case <-ctx.Done():
188-
case <-ticker:
185+
case <-ticker.C:
189186
cancel()
190187
timeout = true
191188
}

internal/gateway/grpc_proxy_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func Test_A(t *testing.T) {
105105
So(res, ShouldBeNil)
106106
So(err.Error(), ShouldContainSubstring, "No leader founded")
107107
time.Sleep(100 * time.Millisecond)
108-
res, err = pingCli.Ping(stdCtx.Background(), &empty.Empty{})
108+
_, err = pingCli.Ping(stdCtx.Background(), &empty.Empty{})
109109
So(err.Error(), ShouldContainSubstring, "Unknown method")
110110
})
111111

@@ -159,6 +159,14 @@ func Test_A(t *testing.T) {
159159
res, err := ebCli.ListEventBus(ctx, &empty.Empty{})
160160
So(err, ShouldBeNil)
161161
So(res.Eventbus, ShouldHaveLength, 4)
162+
So(res.Eventbus[0].Name, ShouldEqual, "battle1")
163+
So(res.Eventbus[0].Id, ShouldEqual, 1)
164+
So(res.Eventbus[1].Name, ShouldEqual, "battle2")
165+
So(res.Eventbus[1].Id, ShouldEqual, 2)
166+
So(res.Eventbus[2].Name, ShouldEqual, "battle3")
167+
So(res.Eventbus[2].Id, ShouldEqual, 3)
168+
So(res.Eventbus[3].Name, ShouldEqual, "battle4")
169+
So(res.Eventbus[3].Id, ShouldEqual, 4)
162170
})
163171

164172
cancel()

0 commit comments

Comments
 (0)