Package list golang-github-go-kit-kit / 513c60c
Fix integration tests for eureka/zk Instancer Yuri Shkuro 4 years ago
4 changed file(s) with 34 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
104104 func (s *Instancer) Deregister(ch chan<- sd.Event) {
105105 s.cache.Deregister(ch)
106106 }
107
108 // state returns the current state of instance.Cache, only for testing
109 func (s *Instancer) state() sd.Event {
110 return s.cache.State()
111 }
5555 defer instancer.Stop()
5656
5757 // We should have one instance immediately after subscriber instantiation.
58 state := instancer.State()
58 state := instancer.state()
5959 if state.Err != nil {
6060 t.Error(state.Err)
6161 }
7373 time.Sleep(2 * time.Second)
7474
7575 // Now we should have two instances.
76 state = instancer.State()
76 state = instancer.state()
7777 if state.Err != nil {
7878 t.Error(state.Err)
7979 }
8888 time.Sleep(2 * time.Second)
8989
9090 // And then there was one.
91 endpoints, err = endpointer.Endpoints()
92 if err != nil {
93 t.Error(err)
91 state = instancer.state()
92 if state.Err != nil {
93 t.Error(state.Err)
9494 }
95 if want, have := 1, len(endpoints); want != have {
95 if want, have := 1, len(state.Instances); want != have {
9696 t.Errorf("want %d, have %d", want, have)
9797 }
9898 }
8787 func (s *Instancer) Deregister(ch chan<- sd.Event) {
8888 s.cache.Deregister(ch)
8989 }
90
91 // state returns the current state of instance.Cache, only for testing
92 func (s *Instancer) state() sd.Event {
93 return s.cache.State()
94 }
3434 }
3535 defer c1.Stop()
3636
37 s, err := NewSubscriber(c1, path, newFactory(""), logger)
37 instancer, err := NewInstancer(c1, path, logger)
3838 if err != nil {
3939 t.Fatalf("Unable to create Subscriber: %v", err)
4040 }
41 defer s.Stop()
42
43 services, err := s.Endpoints()
44 if err != nil {
45 t.Fatal(err)
46 }
47 if want, have := 0, len(services); want != have {
41 defer instancer.Stop()
42
43 state := instancer.state()
44 if state.Err != nil {
45 t.Fatal(err)
46 }
47 if want, have := 0, len(state.Instances); want != have {
4848 t.Errorf("want %d, have %d", want, have)
4949 }
5050
6969 c, _ := NewClient(host, logger)
7070 defer c.Stop()
7171
72 _, err := NewSubscriber(c, "invalid/path", newFactory(""), logger)
72 _, err := NewInstancer(c, "invalid/path", logger)
7373
7474 if want, have := stdzk.ErrInvalidPath, err; want != have {
7575 t.Errorf("want %v, have %v", want, have)
8181 c, _ := NewClient(host, logger, ACL(acl), Credentials("user", "secret"))
8282 defer c.Stop()
8383
84 _, err := NewSubscriber(c, "/acl-issue-test", newFactory(""), logger)
84 _, err := NewInstancer(c, "/acl-issue-test", logger)
8585
8686 if err != nil {
8787 t.Fatal(err)
9393 c, _ := NewClient(host, logger, ACL(acl))
9494 defer c.Stop()
9595
96 _, err := NewSubscriber(c, "/acl-issue-test", newFactory(""), logger)
96 _, err := NewInstancer(c, "/acl-issue-test", logger)
9797
9898 if err != stdzk.ErrNoAuth {
9999 t.Errorf("want %v, have %v", stdzk.ErrNoAuth, err)
104104 c, _ := NewClient(host, logger)
105105 c.Stop()
106106
107 _, err := NewSubscriber(c, "/acl-issue-test", newFactory(""), logger)
107 _, err := NewInstancer(c, "/acl-issue-test", logger)
108108
109109 if err != ErrClientClosed {
110110 t.Errorf("want %v, have %v", ErrClientClosed, err)
122122 defer c1.Stop()
123123
124124 c2, err := NewClient(host, logger)
125 s, err := NewSubscriber(c2, path, newFactory(""), logger)
125 s, err := NewInstancer(c2, path, logger)
126126 if err != nil {
127127 t.Fatal(err)
128128 }
147147
148148 time.Sleep(50 * time.Millisecond)
149149
150 services, err := s.Endpoints()
151 if err != nil {
152 t.Fatal(err)
153 }
154 if want, have := 2, len(services); want != have {
150 state := s.state()
151 if state.Err != nil {
152 t.Fatal(state.Err)
153 }
154 if want, have := 2, len(state.Instances); want != have {
155155 t.Errorf("want %d, have %d", want, have)
156156 }
157157 }