Skip to content

Commit

Permalink
maintain unit case
Browse files Browse the repository at this point in the history
Signed-off-by: joccau <zak.zhao@pingcap.com>
  • Loading branch information
joccau committed Mar 2, 2023
1 parent 52da6da commit 399df3c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion br/pkg/streamhelper/daemon/owner_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (

type anApp struct {
sync.Mutex
begun bool
serviceStart bool
begun bool

tickingMessenger chan struct{}
tickingMessengerOnce *sync.Once
Expand All @@ -35,6 +36,7 @@ func newTestApp(t *testing.T) *anApp {

// OnStart implements daemon.Interface.
func (a *anApp) OnStart(ctx context.Context) {
a.serviceStart = true
}

// OOnBecomeOwner would be called once become the owner.
Expand Down Expand Up @@ -91,6 +93,10 @@ func (a *anApp) Running() bool {
return a.begun
}

func (a *anApp) AssertService(req *require.Assertions, serviceStart bool) {
req.True(a.serviceStart == serviceStart)
}

func (a *anApp) AssertTick(timeout time.Duration) {
a.Lock()
messenger := a.tickingMessenger
Expand Down Expand Up @@ -133,8 +139,10 @@ func TestDaemon(t *testing.T) {
ow := owner.NewMockManager(ctx, "owner_daemon_test")
d := daemon.New(app, ow, 100*time.Millisecond)

app.AssertService(req, false)
f, err := d.Begin(ctx)
req.NoError(err)
app.AssertService(req, true)
go f()
app.AssertStart(1 * time.Second)
app.AssertTick(1 * time.Second)
Expand Down

0 comments on commit 399df3c

Please sign in to comment.