watcher_group_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package grpcproxy
  15. import (
  16. "testing"
  17. "golang.org/x/net/context"
  18. "github.com/coreos/etcd/clientv3"
  19. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  20. )
  21. func TestWatchgroupBroadcast(t *testing.T) {
  22. wch := make(chan clientv3.WatchResponse, 0)
  23. wg := newWatchergroup(wch, nil)
  24. go wg.run()
  25. chs := make([]chan *pb.WatchResponse, 10)
  26. for i := range chs {
  27. chs[i] = make(chan *pb.WatchResponse, 1)
  28. w := watcher{
  29. id: int64(i),
  30. sws: &serverWatchStream{watchCh: chs[i], ctx: context.TODO()},
  31. progress: true,
  32. }
  33. rid := receiverID{streamID: 1, watcherID: w.id}
  34. wg.add(rid, w)
  35. }
  36. // send a progress response
  37. wch <- clientv3.WatchResponse{Header: pb.ResponseHeader{Revision: 1}}
  38. for _, ch := range chs {
  39. <-ch
  40. }
  41. }