Skip to content

Commit

Permalink
Add TestPariticipantStartWithAdvertiseListenAddr
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Shi <[email protected]>
  • Loading branch information
binshi-bing committed Apr 23, 2023
1 parent ca92999 commit 7bd9727
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/integrations/mcs/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ func (tc *TestTSOCluster) AddServer(addr string) error {
if err != nil {
return err
}
err = initLogger(generatedCfg)
err = InitLogger(generatedCfg)
if err != nil {
return err
}
server, cleanup, err := newTSOTestServer(tc.ctx, generatedCfg)
server, cleanup, err := NewTSOTestServer(tc.ctx, generatedCfg)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/mcs/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

var once sync.Once

func initLogger(cfg *tso.Config) (err error) {
func InitLogger(cfg *tso.Config) (err error) {
once.Do(func() {
// Setup the logger.
err = logutil.SetupLogger(cfg.Log, &cfg.Logger, &cfg.LogProps, cfg.Security.RedactInfoLog)
Expand Down Expand Up @@ -88,10 +88,10 @@ func StartSingleTSOTestServer(ctx context.Context, re *require.Assertions, backe
re.NoError(err)

// Setup the logger.
err = initLogger(cfg)
err = InitLogger(cfg)
re.NoError(err)

s, cleanup, err := newTSOTestServer(ctx, cfg)
s, cleanup, err := NewTSOTestServer(ctx, cfg)
re.NoError(err)
testutil.Eventually(re, func() bool {
return !s.IsClosed()
Expand All @@ -100,7 +100,7 @@ func StartSingleTSOTestServer(ctx context.Context, re *require.Assertions, backe
return s, cleanup
}

func newTSOTestServer(ctx context.Context, cfg *tso.Config) (*tso.Server, testutil.CleanupFunc, error) {
func NewTSOTestServer(ctx context.Context, cfg *tso.Config) (*tso.Server, testutil.CleanupFunc, error) {
s := tso.CreateServer(ctx, cfg)
if err := s.Run(); err != nil {
return nil, nil, err
Expand Down
26 changes: 26 additions & 0 deletions tests/integrations/mcs/tso/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,32 @@ func (suite *tsoServerTestSuite) TestTSOServerStartAndStopNormally() {
}
}

func (suite *tsoServerTestSuite) TestPariticipantStartWithAdvertiseListenAddr() {
re := suite.Require()

cfg := tso.NewConfig()
cfg.BackendEndpoints = suite.backendEndpoints
cfg.ListenAddr = tempurl.Alloc()
cfg.AdvertiseListenAddr = tempurl.Alloc()
cfg, err := tso.GenerateConfig(cfg)
re.NoError(err)

// Setup the logger.
err = mcs.InitLogger(cfg)
re.NoError(err)

s, cleanup, err := mcs.NewTSOTestServer(suite.ctx, cfg)
re.NoError(err)
defer cleanup()
testutil.Eventually(re, func() bool {
return s.IsServing()
}, testutil.WithWaitFor(5*time.Second), testutil.WithTickInterval(50*time.Millisecond))

member, err := s.GetMember(utils.DefaultKeyspaceID, utils.DefaultKeyspaceGroupID)
re.NoError(err)
re.Equal(fmt.Sprintf("%s-%05d", cfg.AdvertiseListenAddr, utils.DefaultKeyspaceGroupID), member.Name())
}

func TestTSOPath(t *testing.T) {
re := require.New(t)
checkTSOPath(re, true /*isAPIServiceMode*/)
Expand Down

0 comments on commit 7bd9727

Please sign in to comment.