Skip to content

Commit

Permalink
Fix implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
iegomez committed May 24, 2023
1 parent c9355ba commit ad11e89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 11 additions & 4 deletions backends/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type GRPC struct {
dialOptions []grpc.DialOption
hostname string
timeout int
name string
}

const defaultGRPCTimeoutMs = 500
Expand Down Expand Up @@ -140,11 +141,17 @@ func (o *GRPC) CheckAcl(username, topic, clientid string, acc int32) (bool, erro

// GetName gets the gRPC backend's name.
func (o *GRPC) GetName() string {
resp, err := o.client.GetName(context.Background(), &empty.Empty{})
if err != nil {
return "grpc get name error"
if len(o.name) == 0 {
resp, err := o.client.GetName(context.Background(), &empty.Empty{})

if err != nil {
o.name = "gRPC"
} else {
o.name = resp.Name
}
}
return resp.Name

return o.name
}

// Halt signals the gRPC backend that mosquitto is halting.
Expand Down
6 changes: 6 additions & 0 deletions backends/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ func TestGRPC(t *testing.T) {
auth, err := g.GetUser(grpcUsername, grpcPassword, grpcClientId)
So(err, ShouldNotBeNil)
c.So(auth, ShouldBeFalse)

name := g.GetName()
So(name, ShouldEqual, "gRPC")
})

Convey("it should work after the service comes back up", func(c C) {
Expand All @@ -125,6 +128,9 @@ func TestGRPC(t *testing.T) {
auth, err := g.GetUser(grpcUsername, grpcPassword, grpcClientId)
So(err, ShouldBeNil)
c.So(auth, ShouldBeTrue)

name := g.GetName()
So(name, ShouldEqual, "MyGRPCBackend")
})
})
})
Expand Down

0 comments on commit ad11e89

Please sign in to comment.