mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-04 04:04:00 +00:00
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.
This commit is contained in:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user