From 961c7d4680c58e3b01eedb4361a3fa57a1f9a904 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Thu, 28 Feb 2019 15:54:57 -0500 Subject: [PATCH] database: add test for lock expiration --- database/pgsql/lock_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/database/pgsql/lock_test.go b/database/pgsql/lock_test.go index 62727518..87806ca3 100644 --- a/database/pgsql/lock_test.go +++ b/database/pgsql/lock_test.go @@ -1,4 +1,4 @@ -// Copyright 2016 clair authors +// Copyright 2019 clair authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,8 +19,23 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) +func TestAcquireLockReturnsExistingLockDuration(t *testing.T) { + datastore, tx := openSessionForTest(t, "Lock", true) + defer datastore.Close() + + acquired, originalExpiration, err := tx.AcquireLock("test1", "owner1", time.Minute) + require.Nil(t, err) + require.True(t, acquired) + + acquired2, expiration, err := tx.AcquireLock("test1", "owner2", time.Hour) + require.Nil(t, err) + require.False(t, acquired2) + require.Equal(t, expiration, originalExpiration) +} + func TestLock(t *testing.T) { datastore, tx := openSessionForTest(t, "Lock", true) defer datastore.Close()