From b03c77f2d66eebe404b31e148e656e73b7e28e6b Mon Sep 17 00:00:00 2001 From: akhilac1 Date: Wed, 21 Sep 2022 14:10:04 +0530 Subject: [PATCH] check for maxTimeout to be positive Signed-off-by: akhilac1 --- configuration/postgres/postgres.go | 6 +++--- configuration/postgres/postgres_test.go | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/configuration/postgres/postgres.go b/configuration/postgres/postgres.go index 1d3e74b6b..d2d8bdf6e 100644 --- a/configuration/postgres/postgres.go +++ b/configuration/postgres/postgres.go @@ -58,7 +58,7 @@ const ( unlistenTemplate = "unlisten %s" payloadDataKey = "data" ErrorMissingTableName = "missing postgreSQL configuration table name" - ErrorMissingTable = "postgreSQL configuration table - '%v' does not exist" + ErrorMissingTable = "postgreSQL configuration table - '%s' does not exist" InfoStartInit = "initializing postgreSQL configuration store" ErrorMissingConnectionString = "missing postgreSQL connection string" ErrorAlreadyInitialized = "postgreSQL configuration store already initialized" @@ -203,9 +203,9 @@ func (p *ConfigurationStore) Unsubscribe(ctx context.Context, req *configuration return fmt.Errorf("error listening to channel: %s", err) } delete(p.ActiveSubscriptions, k) + return nil } } - return nil } return fmt.Errorf("unable to find subscription with ID : %v", req.ID) } @@ -310,7 +310,7 @@ func parseMetadata(cmetadata configuration.Metadata) (metadata, error) { } // configure maxTimeout if provided if mxTimeout, ok := cmetadata.Properties[connMaxIdleTimeKey]; ok && mxTimeout != "" { - if t, err := time.ParseDuration(mxTimeout); err == nil { + if t, err := time.ParseDuration(mxTimeout); err == nil && t > 0 { m.maxIdleTimeout = t } } diff --git a/configuration/postgres/postgres_test.go b/configuration/postgres/postgres_test.go index ea0f74947..8a5a18a17 100644 --- a/configuration/postgres/postgres_test.go +++ b/configuration/postgres/postgres_test.go @@ -98,9 +98,7 @@ func TestConnectAndQuery(t *testing.T) { rows := mock.QueryRow(context.Background(), query) var id string err = rows.Scan(&id) - if err != nil { - t.Error(err) - } + assert.Nil(t, err) err = mock.ExpectationsWereMet() assert.Nil(t, err) }