VOL-2624 - fix SCA issues
Change-Id: I3a5e0aafc5b6bd6c6e865675a3481db289a7d772
diff --git a/pkg/db/backend.go b/pkg/db/backend.go
index 9bb49ac..96829c5 100644
--- a/pkg/db/backend.go
+++ b/pkg/db/backend.go
@@ -103,7 +103,7 @@
logger.Debug("update-liveness-channel-reason-change")
b.liveness <- alive
b.lastLivenessTime = time.Now()
- } else if time.Now().Sub(b.lastLivenessTime) > b.LivenessChannelInterval {
+ } else if time.Since(b.lastLivenessTime) > b.LivenessChannelInterval {
logger.Debug("update-liveness-channel-reason-interval")
b.liveness <- alive
b.lastLivenessTime = time.Now()
diff --git a/pkg/db/backend_test.go b/pkg/db/backend_test.go
index 0da95cd..ac1d0df 100644
--- a/pkg/db/backend_test.go
+++ b/pkg/db/backend_test.go
@@ -242,6 +242,7 @@
// Assert that kvstore has this value stored
kvpair, err := backend.Get(ctx, "key1")
+ assert.Nil(t, err)
assert.NotNil(t, kvpair)
assert.Equal(t, defaultPathPrefix+"/key1", kvpair.Key)
assert.Equal(t, []uint8("value1"), kvpair.Value)
@@ -250,6 +251,7 @@
err = backend.Put(ctx, "key1", []uint8("value11"))
assert.Nil(t, err)
kvpair, err = backend.Get(ctx, "key1")
+ assert.Nil(t, err)
assert.NotNil(t, kvpair)
assert.Equal(t, defaultPathPrefix+"/key1", kvpair.Key)
assert.Equal(t, []uint8("value11"), kvpair.Value)
@@ -273,6 +275,7 @@
defer cancel()
backend := provisionBackendWithEmbeddedEtcdServer(t)
err := backend.Put(ctx, "key2", []uint8("value2"))
+ assert.Nil(t, err)
// Assert alive state has become true
assert.True(t, backend.alive)
@@ -286,8 +289,8 @@
// Assert that Get works fine for absent key3
kvpair, err = backend.Get(ctx, "key3")
- assert.Nil(t, kvpair)
assert.Nil(t, err) // no error as lookup is successful
+ assert.Nil(t, kvpair)
}
// Get operation should fail against Dummy Non-existent Etcd Server
@@ -309,18 +312,21 @@
defer cancel()
backend := provisionBackendWithEmbeddedEtcdServer(t)
err := backend.Put(ctx, "key3", []uint8("value3"))
+ assert.Nil(t, err)
// Assert alive state has become true
assert.True(t, backend.alive)
// Assert that kvstore has this key stored
kvpair, err := backend.Get(ctx, "key3")
+ assert.Nil(t, err)
assert.NotNil(t, kvpair)
// Delete and Assert that key has been removed
err = backend.Delete(ctx, "key3")
assert.Nil(t, err)
kvpair, err = backend.Get(ctx, "key3")
+ assert.Nil(t, err)
assert.Nil(t, kvpair)
// Assert that Delete silently ignores absent key3
diff --git a/pkg/db/kvstore/etcdclient.go b/pkg/db/kvstore/etcdclient.go
index a0f39cd..2d126f7 100644
--- a/pkg/db/kvstore/etcdclient.go
+++ b/pkg/db/kvstore/etcdclient.go
@@ -30,7 +30,6 @@
// EtcdClient represents the Etcd KV store client
type EtcdClient struct {
ectdAPI *v3Client.Client
- leaderRev v3Client.Client
keyReservations map[string]*v3Client.LeaseID
watchedChannels sync.Map
writeLock sync.Mutex
@@ -39,9 +38,6 @@
lockToMutexLock sync.Mutex
}
-// Connection Timeout in Seconds
-var connTimeout int = 2
-
// NewEtcdClient returns a new client for the Etcd KV store
func NewEtcdClient(addr string, timeout int) (*EtcdClient, error) {
duration := GetDuration(timeout)