mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
56 lines
2.0 KiB
Go
56 lines
2.0 KiB
Go
package sqlplugin
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/hanzoai/tasks/common/clock"
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/metrics"
|
|
)
|
|
|
|
// TestDatabaseHandleReconnect tests the reconnection behavior when there are connection errors.
|
|
func TestDatabaseHandleReconnect(t *testing.T) {
|
|
testCases := []struct {
|
|
msg string // test description
|
|
numRetries int // number of time to try reconnecting
|
|
retryDelay time.Duration // wait time (in this test) before trying to reconnect
|
|
expectedConnectAttempts int // expected number of times a connection attempt is made.
|
|
}{
|
|
{"No retries", 0, 0, 1},
|
|
{"Retry once immediately", 1, 0, 1},
|
|
{"Retry many times immediately", 5, 0, 1},
|
|
{"Retry once after session retry interval", 1, sessionRefreshMinInternal + time.Millisecond, 2},
|
|
{"Retry many times with session retry interval", 5, sessionRefreshMinInternal + time.Millisecond, 6},
|
|
{"Retry many times quickly - but collectively exceeding session retry interval. Expect 2 total attempts", 5, sessionRefreshMinInternal/5 + time.Millisecond, 2},
|
|
}
|
|
|
|
needsRefreshFunc := func(_ error) bool { return false }
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.msg, func(t *testing.T) {
|
|
actualConnectAttemptCount := 0
|
|
connectFunc := func() (*sqlx.DB, error) {
|
|
actualConnectAttemptCount++
|
|
return nil, errTest
|
|
}
|
|
fakeTimeSource := clock.NewEventTimeSource().Update(time.Now())
|
|
dbHandle := NewDatabaseHandle(DbKindUnknown, connectFunc, needsRefreshFunc, log.NewNoopLogger(), metrics.NoopMetricsHandler, fakeTimeSource)
|
|
assert.NotNil(t, dbHandle)
|
|
|
|
for i := 0; i < tc.numRetries; i++ {
|
|
fakeTimeSource.Advance(tc.retryDelay)
|
|
db, err := dbHandle.DB()
|
|
assert.Nil(t, db, tc.msg)
|
|
assert.ErrorIs(t, err, DatabaseUnavailableError)
|
|
}
|
|
assert.Equal(t, tc.expectedConnectAttempts, actualConnectAttemptCount, tc.msg)
|
|
})
|
|
}
|
|
}
|
|
|
|
var errTest = errors.New("test")
|