Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fail database tests if VISOR_TEST_DB not set #79

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions storage/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
)

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 @@ -43,8 +43,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 @@ -142,8 +142,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 @@ -237,8 +237,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 @@ -345,8 +345,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 @@ -416,8 +416,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 @@ -515,8 +515,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 @@ -582,12 +582,11 @@ func TestMarkTipSetMessagesComplete(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, 1, count)
})

}

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 @@ -785,8 +784,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 Expand Up @@ -852,5 +851,4 @@ func TestMarkGasOutputsMessagesComplete(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, 1, count)
})

}
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