Beispiel #1
0
func shutdownServerAndWait(t *testing.T, s *server.Server) bool {
	listenSpec := s.GetListenEndpoint()
	routeListenSpec := s.GetRouteListenEndpoint()

	s.Shutdown()

	// For now, do this only on Windows. Lots of tests would fail
	// without this because the listen port would linger from one
	// test to another causing failures.
	checkShutdown := func(listen string) bool {
		down := false
		maxTime := time.Now().Add(5 * time.Second)
		for time.Now().Before(maxTime) {
			conn, err := net.Dial("tcp", listen)
			if err != nil {
				down = true
				break
			}
			conn.Close()
			// Retry after 50ms
			time.Sleep(50 * time.Millisecond)
		}
		return down
	}
	if listenSpec != "" {
		if !checkShutdown(listenSpec) {
			return false
		}
	}
	if routeListenSpec != "" {
		if !checkShutdown(routeListenSpec) {
			return false
		}
	}
	return true
}