Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions common/persistence/persistence-tests/persistence_test_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"cmp"
"context"
"fmt"
"math/rand"
"strings"
"sync/atomic"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/suite"
"go.opentelemetry.io/otel/trace"
persistencespb "go.temporal.io/server/api/persistence/v1"
Expand Down Expand Up @@ -129,7 +129,7 @@ func NewTestBaseWithCassandra(options *TestBaseOptions) *TestBase {

func NewTestClusterForCassandra(options *TestBaseOptions, logger log.Logger) *cassandra.TestCluster {
if options.DBName == "" {
options.DBName = "test_" + GenerateRandomDBName(3)
options.DBName = GenerateRandomDBName()
}
testCluster := cassandra.NewTestCluster(options.DBName, options.DBUsername, options.DBPassword, options.DBHost, options.DBPort, options.SchemaDir, options.FaultInjection, logger)
return testCluster
Expand Down Expand Up @@ -436,23 +436,10 @@ func (s *TestBase) RangeDeleteMessagesFromNamespaceDLQ(
return s.NamespaceReplicationQueue.RangeDeleteMessagesFromDLQ(ctx, firstMessageID, lastMessageID)
}

func randString(length int) string {
const lowercaseSet = "abcdefghijklmnopqrstuvwxyz"
b := make([]byte, length)
for i := range b {
b[i] = lowercaseSet[rand.Int63()%int64(len(lowercaseSet))]
}
return string(b)
}

// GenerateRandomDBName helper
// Format: MMDDHHMMSS_abc
func GenerateRandomDBName(n int) string {
var prefix strings.Builder
prefix.WriteString(time.Now().UTC().Format("0102150405"))
prefix.WriteRune('_')
prefix.WriteString(randString(n))
return prefix.String()
func GenerateRandomDBName() string {
uuidPart := strings.ReplaceAll(uuid.NewString(), "-", "")
// Keep generated DB names short enough for Cassandra keyspaces after XDC tests append cluster suffixes.
return "test_" + uuidPart[:24]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main change

}

func timeComparator(t1, t2 time.Time, timeTolerance time.Duration) bool {
Expand Down
10 changes: 5 additions & 5 deletions common/persistence/persistence-tests/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func GetTestClusterOption(storeType, driver string) *TestBaseOptions {
// GetCassandraTestClusterOption returns test options
func GetCassandraTestClusterOption() *TestBaseOptions {
return &TestBaseOptions{
DBName: "test_" + GenerateRandomDBName(3),
DBName: GenerateRandomDBName(),
DBHost: environment.GetCassandraAddress(),
DBPort: environment.GetCassandraPort(),
SchemaDir: testCassandraSchemaDir,
Expand All @@ -66,7 +66,7 @@ func GetCassandraTestClusterOption() *TestBaseOptions {
func GetMySQLTestClusterOption() *TestBaseOptions {
return &TestBaseOptions{
SQLDBPluginName: mysql.PluginName,
DBName: "test_" + GenerateRandomDBName(3),
DBName: GenerateRandomDBName(),
DBUsername: testMySQLUser,
DBPassword: testMySQLPassword,
DBHost: environment.GetMySQLAddress(),
Expand Down Expand Up @@ -94,7 +94,7 @@ func GetPostgreSQLTestClusterOption(
}
return &TestBaseOptions{
SQLDBPluginName: pluginName,
DBName: "test_" + GenerateRandomDBName(3),
DBName: GenerateRandomDBName(),
DBUsername: testPostgreSQLUser,
DBPassword: testPostgreSQLPassword,
DBHost: environment.GetPostgreSQLAddress(),
Expand All @@ -109,7 +109,7 @@ func GetPostgreSQLTestClusterOption(
func GetSQLiteFileTestClusterOption() *TestBaseOptions {
return &TestBaseOptions{
SQLDBPluginName: sqlite.PluginName,
DBName: filepath.Join(os.TempDir(), "test_"+GenerateRandomDBName(3)), // put files in temp to avoid cluttering the project
DBName: filepath.Join(os.TempDir(), GenerateRandomDBName()), // put files in temp to avoid cluttering the project
DBUsername: testSQLiteUser,
DBPassword: testSQLitePassword,
DBHost: environment.GetLocalhostIP(),
Expand All @@ -129,7 +129,7 @@ func GetSQLiteFileTestClusterOption() *TestBaseOptions {
func GetSQLiteMemoryTestClusterOption() *TestBaseOptions {
return &TestBaseOptions{
SQLDBPluginName: sqlite.PluginName,
DBName: "test_" + GenerateRandomDBName(3),
DBName: GenerateRandomDBName(),
DBUsername: testSQLiteUser,
DBPassword: testSQLitePassword,
DBHost: environment.GetLocalhostIP(),
Expand Down
2 changes: 1 addition & 1 deletion common/persistence/tests/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewSQLiteFileConfig() *config.SQL {
ConnectAddr: environment.GetLocalhostIP(),
ConnectProtocol: "tcp",
PluginName: "sqlite",
DatabaseName: "test_" + persistencetests.GenerateRandomDBName(3),
DatabaseName: persistencetests.GenerateRandomDBName(),
ConnectAttributes: map[string]string{"cache": "private"},
}
}
Expand Down
4 changes: 2 additions & 2 deletions tools/sql/clitest/version_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func (s *VersionTestSuite) SetupTest() {

// TestVerifyCompatibleVersion test
func (s *VersionTestSuite) TestVerifyCompatibleVersion() {
database := "temporal_ver_test_" + persistencetests.GenerateRandomDBName(3)
visDatabase := "temporal_vis_ver_test_" + persistencetests.GenerateRandomDBName(3)
database := persistencetests.GenerateRandomDBName()
visDatabase := persistencetests.GenerateRandomDBName()

defer s.createDatabase(database)()
defer s.createDatabase(visDatabase)()
Expand Down
Loading