mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
MySQL/Redis: Test fatal instead of panic
This commit is contained in:
parent
6195227869
commit
2c8068e04b
2 changed files with 22 additions and 4 deletions
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/Icinga/icingadb/config/testbackends"
|
||||
"github.com/Icinga/icingadb/utils"
|
||||
"github.com/go-sql-driver/mysql"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -292,10 +293,18 @@ func TestGetConnectionCheckInterval(t *testing.T) {
|
|||
atomic.StoreUint32(dbw.ConnectionLostCounterAtomic, 11)
|
||||
assert.Equal(t, 60*time.Second, dbw.getConnectionCheckInterval())
|
||||
|
||||
//Should panic, if not connected and counter > 13
|
||||
//Should exit, if not connected and counter > 13
|
||||
dbw.CompareAndSetConnected(false)
|
||||
atomic.StoreUint32(dbw.ConnectionLostCounterAtomic, 14)
|
||||
assert.Panics(t, func() { dbw.getConnectionCheckInterval() }, "Should panic")
|
||||
|
||||
exited := false
|
||||
defer func() { logrus.StandardLogger().ExitFunc = nil }()
|
||||
logrus.StandardLogger().ExitFunc = func(i int) {
|
||||
exited = true
|
||||
}
|
||||
|
||||
dbw.getConnectionCheckInterval()
|
||||
assert.Equal(t, true, exited, "Should have exited")
|
||||
}
|
||||
|
||||
func TestDBWrapper_SqlFetchAll(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package connection
|
|||
import (
|
||||
"github.com/Icinga/icingadb/config/testbackends"
|
||||
"github.com/go-redis/redis"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
|
@ -54,10 +55,18 @@ func TestRDBWrapper_GetConnectionCheckInterval(t *testing.T) {
|
|||
atomic.StoreUint32(rdbw.ConnectionLostCounterAtomic, 11)
|
||||
assert.Equal(t, 60*time.Second, rdbw.getConnectionCheckInterval())
|
||||
|
||||
//Should panic, if not connected and counter > 13
|
||||
//Should exit, if not connected and counter > 13
|
||||
rdbw.CompareAndSetConnected(false)
|
||||
atomic.StoreUint32(rdbw.ConnectionLostCounterAtomic, 14)
|
||||
assert.Panics(t, func() { rdbw.getConnectionCheckInterval() }, "Should panic")
|
||||
|
||||
exited := false
|
||||
defer func() { logrus.StandardLogger().ExitFunc = nil }()
|
||||
logrus.StandardLogger().ExitFunc = func(i int) {
|
||||
exited = true
|
||||
}
|
||||
|
||||
rdbw.getConnectionCheckInterval()
|
||||
assert.Equal(t, true, exited, "Should have exited")
|
||||
}
|
||||
|
||||
func TestRDBWrapper_CheckConnection(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue