mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? Changes version compability checks to pass the real logger, so that the error messages would be seeing in the log ## Why? Before, the error was generic and there were no logs indicating the real error (see https://github.com/temporalio/temporal/issues/7939): ``` sql schema version compatibility check failed: unable to read DB schema version keyspace/database: temporal error: no usable database connection found ``` With this change, the log would contain the actual error: ``` {"level":"error","ts":"2025-07-25T15:30:49.660-0700","msg":"sql handle: unable to refresh database connection pool","error":"pq: no pg_hba.conf entry for host \"127.0.0.1\", ... ``` The alternative solution would be to return the error, but the design of common/persistence/sql/sqlplugin/db_handle.go suggests we hold the abstraction boundaries, by returning generic errors and logging specific errors. ## How did you test it? - [X] built - [X] run locally and tested manually - [X] covered by existing tests
123 lines
3.4 KiB
Go
123 lines
3.4 KiB
Go
package clitest
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
"go.temporal.io/server/common/config"
|
|
"go.temporal.io/server/common/dynamicconfig"
|
|
"go.temporal.io/server/common/log"
|
|
persistencetests "go.temporal.io/server/common/persistence/persistence-tests"
|
|
persistencesql "go.temporal.io/server/common/persistence/sql"
|
|
"go.temporal.io/server/common/primitives"
|
|
"go.temporal.io/server/common/resolver"
|
|
"go.temporal.io/server/tools/sql"
|
|
)
|
|
|
|
type (
|
|
// VersionTestSuite defines a test suite
|
|
VersionTestSuite struct {
|
|
*require.Assertions // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test, not merely log an error
|
|
suite.Suite
|
|
|
|
host string
|
|
port string
|
|
pluginName string
|
|
executionSchemaFileLocation string
|
|
visibilitySchemaFileLocation string
|
|
}
|
|
)
|
|
|
|
// NewVersionTestSuite returns a test suite
|
|
func NewVersionTestSuite(
|
|
host string,
|
|
port string,
|
|
pluginName string,
|
|
executionSchemaFileLocation string,
|
|
visibilitySchemaFileLocation string,
|
|
) *VersionTestSuite {
|
|
return &VersionTestSuite{
|
|
host: host,
|
|
port: port,
|
|
pluginName: pluginName,
|
|
executionSchemaFileLocation: executionSchemaFileLocation,
|
|
visibilitySchemaFileLocation: visibilitySchemaFileLocation,
|
|
}
|
|
}
|
|
|
|
// SetupTest setups test suite
|
|
func (s *VersionTestSuite) SetupTest() {
|
|
s.Assertions = require.New(s.T()) // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil
|
|
}
|
|
|
|
// TestVerifyCompatibleVersion test
|
|
func (s *VersionTestSuite) TestVerifyCompatibleVersion() {
|
|
database := "temporal_ver_test_" + persistencetests.GenerateRandomDBName(3)
|
|
visDatabase := "temporal_vis_ver_test_" + persistencetests.GenerateRandomDBName(3)
|
|
|
|
defer s.createDatabase(database)()
|
|
defer s.createDatabase(visDatabase)()
|
|
err := sql.RunTool([]string{
|
|
"./tool",
|
|
"-ep", s.host,
|
|
"-p", s.port,
|
|
"-u", testUser,
|
|
"-pw", testPassword,
|
|
"-db", database,
|
|
"-pl", s.pluginName,
|
|
"-q",
|
|
"setup-schema",
|
|
"-f", s.executionSchemaFileLocation,
|
|
"-version", "10.0",
|
|
"-o",
|
|
})
|
|
s.NoError(err)
|
|
err = sql.RunTool([]string{
|
|
"./tool",
|
|
"-ep", s.host,
|
|
"-p", s.port,
|
|
"-u", testUser,
|
|
"-pw", testPassword,
|
|
"-db", visDatabase,
|
|
"-pl", s.pluginName,
|
|
"-q",
|
|
"setup-schema",
|
|
"-f", s.visibilitySchemaFileLocation,
|
|
"-version", "10.0",
|
|
"-o",
|
|
})
|
|
s.NoError(err)
|
|
|
|
defaultCfg := config.SQL{
|
|
ConnectAddr: fmt.Sprintf("%v:%v", s.host, s.port),
|
|
User: testUser,
|
|
Password: testPassword,
|
|
PluginName: s.pluginName,
|
|
DatabaseName: database,
|
|
}
|
|
visibilityCfg := defaultCfg
|
|
visibilityCfg.DatabaseName = visDatabase
|
|
cfg := config.Persistence{
|
|
DefaultStore: "default",
|
|
VisibilityStore: "visibility",
|
|
DataStores: map[string]config.DataStore{
|
|
"default": {SQL: &defaultCfg},
|
|
"visibility": {SQL: &visibilityCfg},
|
|
},
|
|
TransactionSizeLimit: dynamicconfig.GetIntPropertyFn(primitives.DefaultTransactionSizeLimit),
|
|
}
|
|
s.NoError(persistencesql.VerifyCompatibleVersion(cfg, resolver.NewNoopResolver(), log.NewNoopLogger()))
|
|
}
|
|
|
|
func (s *VersionTestSuite) createDatabase(database string) func() {
|
|
connection, err := newTestConn("", s.host, s.port, s.pluginName)
|
|
s.NoError(err)
|
|
err = connection.CreateDatabase(database)
|
|
s.NoError(err)
|
|
return func() {
|
|
s.NoError(connection.DropDatabase(database))
|
|
connection.Close()
|
|
}
|
|
}
|