123456789101112131415161718192021222324252627 |
- package internal
- import (
- "sync"
- "testing"
- "github.com/golang/mock/gomock"
- "google.golang.org/grpc/connectivity"
- )
- func TestStateWatcher_watch(t *testing.T) {
- ctrl := gomock.NewController(t)
- defer ctrl.Finish()
- watcher := newStateWatcher()
- var wg sync.WaitGroup
- wg.Add(1)
- watcher.addListener(func() {
- wg.Done()
- })
- conn := NewMocketcdConn(ctrl)
- conn.EXPECT().GetState().Return(connectivity.Ready)
- conn.EXPECT().GetState().Return(connectivity.TransientFailure)
- conn.EXPECT().GetState().Return(connectivity.Ready).AnyTimes()
- conn.EXPECT().WaitForStateChange(gomock.Any(), gomock.Any()).Return(true).AnyTimes()
- go watcher.watch(conn)
- wg.Wait()
- }
|