Files
tasks/common/persistence/tests/persistence_connection_suite.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
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).
2026-03-19 10:36:40 -07:00

77 lines
1.7 KiB
Go

package tests
import (
"context"
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
p "github.com/hanzoai/tasks/common/persistence"
"github.com/hanzoai/tasks/common/persistence/serialization"
"github.com/hanzoai/tasks/common/persistence/sql"
"github.com/hanzoai/tasks/common/persistence/sql/sqlplugin"
)
type (
connectionSuite struct {
suite.Suite
*require.Assertions
factory *sql.Factory
}
)
func newConnectionSuite(
t *testing.T,
factory *sql.Factory,
) *connectionSuite {
return &connectionSuite{
Assertions: require.New(t),
factory: factory,
}
}
func (s *connectionSuite) SetupSuite() {
}
func (s *connectionSuite) TearDownSuite() {
}
func (s *connectionSuite) SetupTest() {
s.Assertions = require.New(s.T())
}
func (s *connectionSuite) TearDownTest() {
}
// Tests that SQL operations do not panic if the underlying connection has been closed and that the persistence layer
// returns a useful error message.
// Currently only run against MySQL and Postgresql (SQLite always maintains at least one open connection)
func (s *connectionSuite) TestClosedConnectionError() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
shardID := (int32)(1)
rangeID := rand.Int63()
shardInfo := RandomShardInfo(shardID, rangeID)
store, err := s.factory.NewShardStore()
s.NoError(err)
store.Close() // Connection will be closed by this call
manager := p.NewShardManager(store, serialization.NewSerializer())
resp, err := manager.GetOrCreateShard(ctx, &p.GetOrCreateShardRequest{
ShardID: shardID,
InitialShardInfo: shardInfo,
})
s.Nil(resp)
s.ErrorContains(err, sqlplugin.DatabaseUnavailableError.Error())
}