Skip to content

Commit

Permalink
Mock watcher that just blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Asim committed Apr 26, 2016
1 parent decb70b commit f7c57fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion registry/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (m *mockRegistry) Deregister(s *registry.Service) error {
}

func (m *mockRegistry) Watch() (registry.Watcher, error) {
return nil, nil
return &mockWatcher{exit: make(chan bool)}, nil
}

func (m *mockRegistry) String() string {
Expand Down
28 changes: 28 additions & 0 deletions registry/mock/mock_watcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package mock

import (
"errors"

"github.com/micro/go-micro/registry"
)

type mockWatcher struct {
exit chan bool
}

func (m *mockWatcher) Next() (*registry.Result, error) {
// not implement so we just block until exit
select {
case <-m.exit:
return nil, errors.New("watcher stopped")
}
}

func (m *mockWatcher) Stop() {
select {
case <-m.exit:
return
default:
close(m.exit)
}
}

0 comments on commit f7c57fd

Please sign in to comment.