Files
tasks/common/persistence/sql/sqlplugin/db_handle_test.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

56 lines
2.0 KiB
Go

package sqlplugin
import (
"errors"
"testing"
"time"
"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/assert"
"go.temporal.io/server/common/clock"
"go.temporal.io/server/common/log"
"go.temporal.io/server/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(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")