diff --git a/cmd/tendermint/commands/reindex_event_test.go b/cmd/tendermint/commands/reindex_event_test.go index 452a6b2a8..c76ce6d9a 100644 --- a/cmd/tendermint/commands/reindex_event_test.go +++ b/cmd/tendermint/commands/reindex_event_test.go @@ -15,6 +15,8 @@ import ( "github.com/tendermint/tendermint/internal/state/mocks" prototmstate "github.com/tendermint/tendermint/proto/tendermint/state" "github.com/tendermint/tendermint/types" + + _ "github.com/lib/pq" // for the psql sink ) const ( diff --git a/internal/state/indexer/sink/psql/psql.go b/internal/state/indexer/sink/psql/psql.go index 4db6f4435..18e95b97d 100644 --- a/internal/state/indexer/sink/psql/psql.go +++ b/internal/state/indexer/sink/psql/psql.go @@ -39,6 +39,8 @@ func NewEventSink(connStr, chainID string) (*EventSink, error) { db, err := sql.Open(driverName, connStr) if err != nil { return nil, err + } else if err := db.Ping(); err != nil { + return nil, err } return &EventSink{ diff --git a/node/node_test.go b/node/node_test.go index 0ea910d2f..b3c651cba 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -568,49 +568,16 @@ func TestNodeSetEventSink(t *testing.T) { assert.Nil(t, ns) assert.Equal(t, errors.New("the psql connection settings cannot be empty"), err) - var psqlConn = "test" - - cfg.TxIndex.Indexer = []string{"psql"} - cfg.TxIndex.PsqlConn = psqlConn - eventSinks = setupTest(t, cfg) - - assert.Equal(t, 1, len(eventSinks)) - assert.Equal(t, indexer.PSQL, eventSinks[0].Type()) - - cfg.TxIndex.Indexer = []string{"psql", "kv"} - cfg.TxIndex.PsqlConn = psqlConn - eventSinks = setupTest(t, cfg) - - assert.Equal(t, 2, len(eventSinks)) - // we use map to filter the duplicated sinks, so it's not guarantee the order when append sinks. - if eventSinks[0].Type() == indexer.KV { - assert.Equal(t, indexer.PSQL, eventSinks[1].Type()) - } else { - assert.Equal(t, indexer.PSQL, eventSinks[0].Type()) - assert.Equal(t, indexer.KV, eventSinks[1].Type()) - } - - cfg.TxIndex.Indexer = []string{"kv", "psql"} - cfg.TxIndex.PsqlConn = psqlConn - eventSinks = setupTest(t, cfg) - - assert.Equal(t, 2, len(eventSinks)) - if eventSinks[0].Type() == indexer.KV { - assert.Equal(t, indexer.PSQL, eventSinks[1].Type()) - } else { - assert.Equal(t, indexer.PSQL, eventSinks[0].Type()) - assert.Equal(t, indexer.KV, eventSinks[1].Type()) - } + // N.B. We can't create a PSQL event sink without starting a postgres + // instance for it to talk to. The indexer service tests exercise that case. var e = errors.New("found duplicated sinks, please check the tx-index section in the config.toml") - cfg.TxIndex.Indexer = []string{"psql", "kv", "Kv"} - cfg.TxIndex.PsqlConn = psqlConn + cfg.TxIndex.Indexer = []string{"null", "kv", "Kv"} _, err = newDefaultNode(cfg, logger) require.Error(t, err) assert.Equal(t, e, err) - cfg.TxIndex.Indexer = []string{"Psql", "kV", "kv", "pSql"} - cfg.TxIndex.PsqlConn = psqlConn + cfg.TxIndex.Indexer = []string{"Null", "kV", "kv", "nUlL"} _, err = newDefaultNode(cfg, logger) require.Error(t, err) assert.Equal(t, e, err)