Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ValyaB committed Sep 17, 2024
1 parent 4ae6765 commit 18806c7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func Get() Config {
v.MustBindEnv("podmetadata.nodename", "NODE_NAME")
v.MustBindEnv("podmetadata.podname", "POD_NAME")

v.MustBindEnv("keepalive", "KEEP_ALIVE")
v.MustBindEnv("keepalivetimeout", "KEEP_ALIVE_TIMEOUT")
_ = v.BindEnv("keepalive", "KEEP_ALIVE")
_ = v.BindEnv("keepalivetimeout", "KEEP_ALIVE_TIMEOUT")

_ = v.BindEnv("log.level", "LOG_LEVEL")

Expand Down
5 changes: 2 additions & 3 deletions internal/proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ func (c *Client) run(ctx context.Context, stream cloudproxyv1alpha.CloudProxyAPI
case <-ctx.Done():
return ctx.Err()
case <-stream.Context().Done():
return fmt.Errorf("stream closed")
return fmt.Errorf("stream closed %w", stream.Context().Err())
case <-time.After(time.Duration(c.keepAlive.Load())):
if !c.isAlive() {
if c.lastSeenError.Load() != nil {
err := c.lastSeenError.Load()
if err := c.lastSeenError.Load(); err != nil {
return fmt.Errorf("recived error: %w", *err)
}
return fmt.Errorf("last seen too old, closing stream")
Expand Down
17 changes: 16 additions & 1 deletion internal/proxy/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,21 @@ func TestClient_run(t *testing.T) {
wantLastSeenUpdated: true,
wantErr: true,
},
{
name: "stream not alive",
args: args{
ctx: func() context.Context {
return context.Background()
},
tuneMockStream: func(m *mock_proxy.MockCloudProxyAPI_StreamCloudProxyClient) {
m.EXPECT().Send(gomock.Any()).Return(nil).AnyTimes() // expected 0 or 1 times
m.EXPECT().Context().Return(context.Background()).AnyTimes() // expected 0 or 1 times
m.EXPECT().Recv().Return(nil, fmt.Errorf("test error"))
},
},
wantLastSeenUpdated: false,
wantErr: true,
},
}
for _, tt := range tests {
tt := tt
Expand All @@ -455,7 +470,7 @@ func TestClient_run(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

c := New(nil, nil, logrus.New(), "clusterID", "version", time.Second, time.Minute)
c := New(nil, nil, logrus.New(), "clusterID", "version", time.Second, time.Second)
stream := mock_proxy.NewMockCloudProxyAPI_StreamCloudProxyClient(ctrl)
if tt.args.tuneMockStream != nil {
tt.args.tuneMockStream(stream)
Expand Down

0 comments on commit 18806c7

Please sign in to comment.