Browse Source

Fix incorrect tests using the PSQL sink. (#7349)

Some of our tests were creating a psql event sink and expecting
it to report (or not report) certain kinds of errors. These tests
were ill-founded in a couple of ways:

1. Tests that required the Postgres driver were not loading it.
   This led to spurious successes on tests that wanted "some error"
   from the sink constructor, but didn't exercise the right path.

2. Tests that wanted a Postgres sink to succeed without a database.
   These tests "passed" because they weren't actually establishing a
   connection to the database, but if they had would have failed for
   the lack of one.

To fix this:
- Load the postgres driver in tests that need it.
- Verify connectivity before reporting successful creation of a PSQL event sink.
- Remove tests that wanted a psql sink without a database, since that case
  is already tested elsewhere.
pull/7356/head
M. J. Fromberger 2 years ago
committed by GitHub
parent
commit
ab1788b922
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 37 deletions
  1. +2
    -0
      cmd/tendermint/commands/reindex_event_test.go
  2. +2
    -0
      internal/state/indexer/sink/psql/psql.go
  3. +4
    -37
      node/node_test.go

+ 2
- 0
cmd/tendermint/commands/reindex_event_test.go View File

@ -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 (


+ 2
- 0
internal/state/indexer/sink/psql/psql.go View File

@ -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{


+ 4
- 37
node/node_test.go View File

@ -636,50 +636,17 @@ func TestNodeSetEventSink(t *testing.T) {
assert.Contains(t, err.Error(), "the psql connection settings cannot be empty")
t.Cleanup(cleanup(ns))
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"}
ns, err = newDefaultNode(ctx, cfg, logger)
require.Error(t, err)
assert.Contains(t, err.Error(), e.Error())
t.Cleanup(cleanup(ns))
cfg.TxIndex.Indexer = []string{"Psql", "kV", "kv", "pSql"}
cfg.TxIndex.PsqlConn = psqlConn
cfg.TxIndex.Indexer = []string{"Null", "kV", "kv", "nUlL"}
ns, err = newDefaultNode(ctx, cfg, logger)
require.Error(t, err)
assert.Contains(t, err.Error(), e.Error())


Loading…
Cancel
Save