statewatcher_test.go 665 B

123456789101112131415161718192021222324252627
  1. package internal
  2. import (
  3. "sync"
  4. "testing"
  5. "github.com/golang/mock/gomock"
  6. "google.golang.org/grpc/connectivity"
  7. )
  8. func TestStateWatcher_watch(t *testing.T) {
  9. ctrl := gomock.NewController(t)
  10. defer ctrl.Finish()
  11. watcher := newStateWatcher()
  12. var wg sync.WaitGroup
  13. wg.Add(1)
  14. watcher.addListener(func() {
  15. wg.Done()
  16. })
  17. conn := NewMocketcdConn(ctrl)
  18. conn.EXPECT().GetState().Return(connectivity.Ready)
  19. conn.EXPECT().GetState().Return(connectivity.TransientFailure)
  20. conn.EXPECT().GetState().Return(connectivity.Ready).AnyTimes()
  21. conn.EXPECT().WaitForStateChange(gomock.Any(), gomock.Any()).Return(true).AnyTimes()
  22. go watcher.watch(conn)
  23. wg.Wait()
  24. }