Skip to content

Commit

Permalink
database: add test for lock expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie committed Feb 28, 2019
1 parent a4e7873 commit 961c7d4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion database/pgsql/lock_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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()
Expand Down

0 comments on commit 961c7d4

Please sign in to comment.