func waitMsgReceived(uri string, app *test.TestApp, expectedToBeFound bool, timeout time.Duration) bool { interval := time.Millisecond * 50 repetitions := int(timeout / interval) for j := 0; j < repetitions; j++ { resp, err := http.Get(uri) if err == nil { switch resp.StatusCode { case http.StatusOK: bytes, err := ioutil.ReadAll(resp.Body) resp.Body.Close() Ω(err).ShouldNot(HaveOccurred()) routes := make(map[string][]string) err = json.Unmarshal(bytes, &routes) Ω(err).ShouldNot(HaveOccurred()) route := routes[string(app.Urls()[0])] if expectedToBeFound { if route != nil { return true } } else { if route == nil { return true } } default: println("Failed to receive routes: ", resp.StatusCode, uri) } } time.Sleep(interval) } return false }
func waitMsgReceived(registry *registry.RouteRegistry, app *test.TestApp, expectedToBeFound bool, timeout time.Duration) bool { interval := time.Millisecond * 50 repetitions := int(timeout / interval) for j := 0; j < repetitions; j++ { if j > 0 { time.Sleep(interval) } received := true for _, url := range app.Urls() { pool := registry.Lookup(url) if expectedToBeFound && pool == nil { received = false break } else if !expectedToBeFound && pool != nil { received = false break } } if received { return true } } return false }
func (s *IntegrationSuite) waitMsgReceived(a *test.TestApp, shouldBeRegistered bool, t time.Duration) bool { registeredOrUnregistered := make(chan bool) go func() { for { received := true for _, v := range a.Urls() { _, ok := s.router.registry.Lookup(v) if ok != shouldBeRegistered { received = false break } } if received { registeredOrUnregistered <- true break } time.Sleep(50 * time.Millisecond) } }() select { case <-registeredOrUnregistered: return true case <-time.After(t): return false } }
func appUnregistered(registry *registry.RouteRegistry, app *test.TestApp) bool { for _, url := range app.Urls() { pool := registry.Lookup(url) if pool != nil { return false } } return true }
func (s *IntegrationSuite) waitMsgReceived(a *test.TestApp, r bool, t time.Duration) bool { i := time.Millisecond * 50 m := int(t / i) for j := 0; j < m; j++ { received := true for _, v := range a.Urls() { _, ok := s.router.registry.Lookup(v) if ok != r { received = false break } } if received { return true } time.Sleep(i) } return false }
func (s *RouterSuite) waitMsgReceived(app *test.TestApp, expectedToBeFound bool, timeout time.Duration) bool { interval := time.Millisecond * 50 repetitions := int(timeout / interval) for j := 0; j < repetitions; j++ { received := true for _, url := range app.Urls() { _, ok := s.router.registry.Lookup(url) if ok != expectedToBeFound { received = false break } } if received { return true } time.Sleep(interval) } return false }
func appUnregistered(routesUri string, app *test.TestApp) bool { routeFound, err := routeExists(routesUri, string(app.Urls()[0])) return err == nil && !routeFound }
var emptyTime time.Time var emptyDuration vcap.Duration Expect(varz.Type).To(Equal("Router")) Expect(varz.Index).To(Equal(uint(2))) Expect(varz.UUID).ToNot(Equal("")) Expect(varz.StartTime).ToNot(Equal(emptyTime)) Expect(varz.Uptime).ToNot(Equal(emptyDuration)) verify_var_z(varz.Host, varz.Credentials[0], varz.Credentials[1]) verify_health_z(varz.Host, registry) }) Context("Register and Unregister", func() { var app *test.TestApp assertRegisterUnregister := func() { app.Listen() Eventually(func() bool { return appRegistered(registry, app) }).Should(BeTrue()) app.VerifyAppStatus(200) app.Unregister() Eventually(func() bool { return appUnregistered(registry, app) }).Should(BeTrue())