fix (db): Clean up tests a bit (#1669)

This commit is contained in:
Jim authored and GitHub committed 2021-11-05 08:51:12 -04:00
1 parent f2ad4de554
commit b6ad76e4d2
2 files changed
+19 -3

No files matched your search

@@ -24,6 +24,8 @@ func TestTrySharedLock(t *testing.T) {
require.NoError(t, err)
d2, err := common.SqlOpen(dbtest.Postgres, u)
require.NoError(t, err)
p2, err := postgres.New(ctx, d2)
require.NoError(t, err)
@@ -47,6 +49,8 @@ func TestTryLock(t *testing.T) {
require.NoError(t, err)
d2, err := common.SqlOpen(dbtest.Postgres, u)
require.NoError(t, err)
p2, err := postgres.New(ctx, d2)
require.NoError(t, err)
@@ -56,7 +60,9 @@ func TestTryLock(t *testing.T) {
err = p2.TryLock(ctx)
require.Error(t, err)
ctx2, _ := context.WithTimeout(ctx, time.Millisecond)
ctx2, cancel := context.WithTimeout(ctx, time.Millisecond)
defer cancel()
err = p2.Lock(ctx2)
require.Error(t, err)
}
@@ -74,6 +80,8 @@ func TestLock(t *testing.T) {
require.NoError(t, err)
d2, err := common.SqlOpen(dbtest.Postgres, u)
require.NoError(t, err)
p2, err := postgres.New(ctx, d2)
require.NoError(t, err)
@@ -83,7 +91,9 @@ func TestLock(t *testing.T) {
err = p2.TryLock(ctx)
require.Error(t, err)
ctx2, _ := context.WithTimeout(ctx, time.Millisecond)
ctx2, cancel := context.WithTimeout(ctx, time.Millisecond)
defer cancel()
err = p2.Lock(ctx2)
require.Error(t, err)
}
@@ -100,6 +110,8 @@ func TestUnlock(t *testing.T) {
require.NoError(t, err)
d2, err := common.SqlOpen(dbtest.Postgres, u)
require.NoError(t, err)
p2, err := postgres.New(ctx, d2)
require.NoError(t, err)
@@ -121,6 +133,7 @@ func TestUnlock(t *testing.T) {
// clear lock on p2
err = p2.Unlock(ctx)
require.NoError(t, err)
// p can now get lock
err = p.TryLock(ctx)
@@ -138,6 +151,8 @@ func TestUnlockShared(t *testing.T) {
require.NoError(t, err)
d2, err := common.SqlOpen(dbtest.Postgres, u)
require.NoError(t, err)
p2, err := postgres.New(ctx, d2)
require.NoError(t, err)
@@ -13,7 +13,7 @@ import (
// setup is a helper function for tests.
// It creates a new database using Template1, establishes an connection,
// and returns a *postgres.Postgrs.
// and returns a *postgres.Postgres.
// It also returns the underlying sql.DB and connection url so tests
// can establish additional connections if necessary.
func setup(ctx context.Context, t *testing.T) (*postgres.Postgres, *sql.DB, string) {
@@ -30,6 +30,7 @@ func setup(ctx context.Context, t *testing.T) (*postgres.Postgres, *sql.DB, stri
require.NoError(t, d.Close())
})
p, err := postgres.New(ctx, d)
require.NoError(t, err)
return p, d, u
}