From 1b8db6a34e5c842ee2e47fda7bb7a468c0717a25 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 15 Jul 2020 15:56:03 +0300 Subject: [PATCH 1/3] Set interval to 10 sec --- pkg/visor/init.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/visor/init.go b/pkg/visor/init.go index f91b766f6d..ef9236b81a 100644 --- a/pkg/visor/init.go +++ b/pkg/visor/init.go @@ -416,7 +416,7 @@ func initHypervisors(v *Visor) bool { } func initUptimeTracker(v *Visor) bool { - const tickDuration = time.Second + const tickDuration = 10 * time.Second report := v.makeReporter("uptime_tracker") conf := v.conf.UptimeTracker From c7a47c6a185d7ca8f4ea448c85068b3a85845a43 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Wed, 15 Jul 2020 17:08:58 +0300 Subject: [PATCH 2/3] Pass uptime value with the request --- internal/utclient/client.go | 6 +++--- internal/utclient/client_test.go | 4 ++-- internal/utclient/mock_api_client.go | 17 +++++++---------- pkg/app/appevent/mock_rpc_client.go | 10 +++------- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/internal/utclient/client.go b/internal/utclient/client.go index 7bc5db4904..f469956cd6 100644 --- a/internal/utclient/client.go +++ b/internal/utclient/client.go @@ -28,7 +28,7 @@ type Error struct { // APIClient implements uptime tracker API client. type APIClient interface { - UpdateVisorUptime(context.Context) error + UpdateVisorUptime(ctx context.Context, seconds int) error Health(ctx context.Context) (int, error) } @@ -65,8 +65,8 @@ func (c *httpClient) Get(ctx context.Context, path string) (*http.Response, erro } // UpdateVisorUptime updates visor uptime. -func (c *httpClient) UpdateVisorUptime(ctx context.Context) error { - resp, err := c.Get(ctx, "/update") +func (c *httpClient) UpdateVisorUptime(ctx context.Context, seconds int) error { + resp, err := c.Get(ctx, fmt.Sprintf("/update?seconds=%d", seconds)) if err != nil { return err } diff --git a/internal/utclient/client_test.go b/internal/utclient/client_test.go index 0a58b1b65a..b789c81a49 100644 --- a/internal/utclient/client_test.go +++ b/internal/utclient/client_test.go @@ -67,10 +67,10 @@ func TestUpdateVisorUptime(t *testing.T) { c, err := NewHTTP(srv.URL, testPubKey, testSecKey) require.NoError(t, err) - err = c.UpdateVisorUptime(context.TODO()) + err = c.UpdateVisorUptime(context.TODO(), 15) require.NoError(t, err) - assert.Equal(t, "/update", <-urlCh) + assert.Equal(t, "/update?seconds=15", <-urlCh) } func authHandler(next http.Handler) http.Handler { diff --git a/internal/utclient/mock_api_client.go b/internal/utclient/mock_api_client.go index 42f06f07b2..b2760b777c 100644 --- a/internal/utclient/mock_api_client.go +++ b/internal/utclient/mock_api_client.go @@ -2,11 +2,8 @@ package utclient -import ( - context "context" - - mock "github.com/stretchr/testify/mock" -) +import context "context" +import mock "github.com/stretchr/testify/mock" // MockAPIClient is an autogenerated mock type for the APIClient type type MockAPIClient struct { @@ -34,13 +31,13 @@ func (_m *MockAPIClient) Health(ctx context.Context) (int, error) { return r0, r1 } -// UpdateVisorUptime provides a mock function with given fields: _a0 -func (_m *MockAPIClient) UpdateVisorUptime(_a0 context.Context) error { - ret := _m.Called(_a0) +// UpdateVisorUptime provides a mock function with given fields: ctx, seconds +func (_m *MockAPIClient) UpdateVisorUptime(ctx context.Context, seconds int) error { + ret := _m.Called(ctx, seconds) var r0 error - if rf, ok := ret.Get(0).(func(context.Context) error); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(context.Context, int) error); ok { + r0 = rf(ctx, seconds) } else { r0 = ret.Error(0) } diff --git a/pkg/app/appevent/mock_rpc_client.go b/pkg/app/appevent/mock_rpc_client.go index c73a4321ee..56264a8e18 100644 --- a/pkg/app/appevent/mock_rpc_client.go +++ b/pkg/app/appevent/mock_rpc_client.go @@ -2,13 +2,9 @@ package appevent -import ( - context "context" - - mock "github.com/stretchr/testify/mock" - - appcommon "github.com/SkycoinProject/skywire-mainnet/pkg/app/appcommon" -) +import appcommon "github.com/SkycoinProject/skywire-mainnet/pkg/app/appcommon" +import context "context" +import mock "github.com/stretchr/testify/mock" // MockRPCClient is an autogenerated mock type for the RPCClient type type MockRPCClient struct { From 0c9fffb544cb495d5e5cc6cc1e4bdecb439c4af0 Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Thu, 16 Jul 2020 12:52:23 +0300 Subject: [PATCH 3/3] Fix client, regenerate mock --- internal/utclient/client.go | 6 +++--- internal/utclient/client_test.go | 4 ++-- internal/utclient/mock_api_client.go | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/utclient/client.go b/internal/utclient/client.go index f469956cd6..61b9e20432 100644 --- a/internal/utclient/client.go +++ b/internal/utclient/client.go @@ -28,7 +28,7 @@ type Error struct { // APIClient implements uptime tracker API client. type APIClient interface { - UpdateVisorUptime(ctx context.Context, seconds int) error + UpdateVisorUptime(context.Context) error Health(ctx context.Context) (int, error) } @@ -65,8 +65,8 @@ func (c *httpClient) Get(ctx context.Context, path string) (*http.Response, erro } // UpdateVisorUptime updates visor uptime. -func (c *httpClient) UpdateVisorUptime(ctx context.Context, seconds int) error { - resp, err := c.Get(ctx, fmt.Sprintf("/update?seconds=%d", seconds)) +func (c *httpClient) UpdateVisorUptime(ctx context.Context) error { + resp, err := c.Get(ctx, "/v2/update") if err != nil { return err } diff --git a/internal/utclient/client_test.go b/internal/utclient/client_test.go index b789c81a49..81a00cd3ae 100644 --- a/internal/utclient/client_test.go +++ b/internal/utclient/client_test.go @@ -67,10 +67,10 @@ func TestUpdateVisorUptime(t *testing.T) { c, err := NewHTTP(srv.URL, testPubKey, testSecKey) require.NoError(t, err) - err = c.UpdateVisorUptime(context.TODO(), 15) + err = c.UpdateVisorUptime(context.TODO()) require.NoError(t, err) - assert.Equal(t, "/update?seconds=15", <-urlCh) + assert.Equal(t, "/v2/update", <-urlCh) } func authHandler(next http.Handler) http.Handler { diff --git a/internal/utclient/mock_api_client.go b/internal/utclient/mock_api_client.go index b2760b777c..8252bd4924 100644 --- a/internal/utclient/mock_api_client.go +++ b/internal/utclient/mock_api_client.go @@ -31,13 +31,13 @@ func (_m *MockAPIClient) Health(ctx context.Context) (int, error) { return r0, r1 } -// UpdateVisorUptime provides a mock function with given fields: ctx, seconds -func (_m *MockAPIClient) UpdateVisorUptime(ctx context.Context, seconds int) error { - ret := _m.Called(ctx, seconds) +// UpdateVisorUptime provides a mock function with given fields: _a0 +func (_m *MockAPIClient) UpdateVisorUptime(_a0 context.Context) error { + ret := _m.Called(_a0) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, int) error); ok { - r0 = rf(ctx, seconds) + if rf, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = rf(_a0) } else { r0 = ret.Error(0) }