Skip to content

Commit

Permalink
chore: fail database tests if VISOR_TEST_DB not set (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
iand authored Oct 8, 2020
1 parent 582fa77 commit d22c545
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
36 changes: 18 additions & 18 deletions storage/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestNoDuplicateSchemaMigrations(t *testing.T) {
}

func TestSchemaIsCurrent(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand All @@ -54,8 +54,8 @@ func TestSchemaIsCurrent(t *testing.T) {
}

func TestLeaseStateChanges(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down Expand Up @@ -153,8 +153,8 @@ func TestLeaseStateChanges(t *testing.T) {
}

func TestMarkStateChangeComplete(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down Expand Up @@ -248,8 +248,8 @@ func truncateVisorProcessingTables(tb testing.TB, db *pg.DB) {
}

func TestLeaseActors(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down Expand Up @@ -356,8 +356,8 @@ func TestLeaseActors(t *testing.T) {
}

func TestMarkActorComplete(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down Expand Up @@ -427,8 +427,8 @@ func TestMarkActorComplete(t *testing.T) {
}

func TestLeaseBlockMessages(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down Expand Up @@ -526,8 +526,8 @@ func TestLeaseBlockMessages(t *testing.T) {
}

func TestMarkTipSetMessagesComplete(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down Expand Up @@ -596,8 +596,8 @@ func TestMarkTipSetMessagesComplete(t *testing.T) {
}

func TestLeaseGasOutputsMessages(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down Expand Up @@ -795,8 +795,8 @@ func TestLeaseGasOutputsMessages(t *testing.T) {
}

func TestMarkGasOutputsMessagesComplete(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
Expand Down
5 changes: 2 additions & 3 deletions tasks/actorstate/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func init() {
}

func TestGenesisProcessor(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
Expand Down Expand Up @@ -122,7 +122,6 @@ func TestGenesisProcessor(t *testing.T) {
require.NoError(t, err)
assert.NotEqual(t, 0, count)
})

}

// truncateGenesisTables ensures the indexing tables are empty
Expand Down
5 changes: 2 additions & 3 deletions tasks/indexer/chainheadindexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func init() {
}

func TestChainHeadIndexer(t *testing.T) {
if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
Expand Down Expand Up @@ -159,7 +159,6 @@ func TestChainHeadIndexer(t *testing.T) {
assert.True(t, exists, "tsk: %s", tsk)
}
})

}

type blockHeaderList []*types.BlockHeader
Expand Down
8 changes: 2 additions & 6 deletions tasks/indexer/chainhistoryindexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

apitest "github.com/filecoin-project/lotus/api/test"
nodetest "github.com/filecoin-project/lotus/node/test"
logging "github.com/ipfs/go-log/v2"

"github.com/go-pg/pg/v10"
"github.com/stretchr/testify/assert"
Expand All @@ -21,10 +20,8 @@ import (
)

func TestChainHistoryIndexer(t *testing.T) {
logging.SetLogLevel("*", "debug")

if testing.Short() || !testutil.DatabaseAvailable() {
t.Skip("short testing requested or VISOR_TEST_DB not set")
if testing.Short() {
t.Skip("short testing requested")
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
Expand Down Expand Up @@ -136,5 +133,4 @@ func TestChainHistoryIndexer(t *testing.T) {
assert.True(t, exists, "tsk: %s", tsk)
}
})

}
8 changes: 5 additions & 3 deletions testutil/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Database() string {
// WaitForExclusiveDatabase waits for exclusive access to the test database until the context is done or the
// exclusive access is granted. It returns a cleanup function that should be called to close the database connection.
func WaitForExclusiveDatabase(ctx context.Context, tb testing.TB) (*pg.DB, func() error, error) {
require.NotEmpty(tb, testDatabase, "set VISOR_TEST_DB")
require.NotEmpty(tb, testDatabase, "No test database available: VISOR_TEST_DB not set")

opt, err := pg.ParseURL(testDatabase)
require.NoError(tb, err)
Expand All @@ -50,8 +50,10 @@ func WaitForExclusiveDatabase(ctx context.Context, tb testing.TB) (*pg.DB, func(
return db, cleanup, nil
}

const testDatabaseLockID = 88899888
const testDatabaseLockCheckInterval = 2 * time.Millisecond
const (
testDatabaseLockID = 88899888
testDatabaseLockCheckInterval = 2 * time.Millisecond
)

// WaitForExclusiveDatabaseLock waits for a an exclusive lock on the test database until the context is done or the
// exclusive access is granted. It returns a cleanup function that should be called to release the exclusive lock. In any
Expand Down

0 comments on commit d22c545

Please sign in to comment.