示例#1
0
文件: net_test.go 项目: hudl/fargo
func shouldBearHTTPStatusCode(actual interface{}, expected ...interface{}) string {
	expectedCode := expected[0]
	code, present := fargo.HTTPResponseStatusCode(actual.(error))
	if !present {
		return fmt.Sprintf("Expected: %d\nActual:   no HTTP status code", expectedCode)
	}
	if code != expectedCode {
		return fmt.Sprintf("Expected: %d\nActual:   %d", expectedCode, code)
	}
	return ""
}
示例#2
0
文件: net_test.go 项目: hudl/fargo
func withCustomRegisteredInstance(e *fargo.EurekaConnection, application string, hostName string, f func(i *fargo.Instance)) func() {
	return func() {
		vipAddress := "app"
		i := &fargo.Instance{
			HostName:         hostName,
			Port:             9090,
			App:              application,
			IPAddr:           "127.0.0.10",
			VipAddress:       vipAddress,
			DataCenterInfo:   fargo.DataCenterInfo{Name: fargo.MyOwn},
			SecureVipAddress: vipAddress,
			Status:           fargo.UP,
			LeaseInfo: fargo.LeaseInfo{
				DurationInSecs: 90,
			},
		}
		So(e.ReregisterInstance(i), ShouldBeNil)

		var wg sync.WaitGroup
		stop := make(chan struct{})
		wg.Add(1)
		go func() {
			defer wg.Done()
			ticker := time.NewTicker(30 * time.Second)
			defer ticker.Stop()
			for {
				select {
				case <-stop:
					return
				case <-ticker.C:
					if err := e.HeartBeatInstance(i); err != nil {
						if code, ok := fargo.HTTPResponseStatusCode(err); ok && code == http.StatusNotFound {
							e.ReregisterInstance(i)
						}
					}
				}
			}
		}()

		Reset(func() {
			close(stop)
			wg.Wait()
			So(e.DeregisterInstance(i), ShouldBeNil)
		})

		f(i)
	}
}
示例#3
0
文件: net_test.go 项目: hudl/fargo
func shouldNotBearAnHTTPStatusCode(actual interface{}, expected ...interface{}) string {
	if code, present := fargo.HTTPResponseStatusCode(actual.(error)); present {
		return fmt.Sprintf("Expected: no HTTP status code\nActual:   %d", code)
	}
	return ""
}