func ServiceAvailable(port uint) bool {
	address, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("localhost:%d", port))
	if err != nil {
		return false
	}

	return availability.Check(address, 10*time.Second) == nil
}
		})

		Context("when the processmonitor has received USR1", func() {
			BeforeEach(func() {
				monitorSession.Signal(syscall.SIGUSR1)

				helpers.KillRedisProcess(instanceID, brokerConfig)

				allowTimeForProcessMonitorToRestartInstances()
			})

			It("does not restart the instance", func() {
				address, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("localhost:%d", port))
				Ω(err).NotTo(HaveOccurred())

				err = availability.Check(address, 2*time.Second)
				Ω(err).To(HaveOccurred())
			})

			AfterEach(func() {
				brokerClient.DeprovisionInstance(instanceID)
				relaunchProcessMonitorWithConfig(processMonitorPath, "broker.yml")
			})
		})
	})
})

func durationForProcessMonitorToRestartInstance() time.Duration {
	return time.Second * time.Duration(brokerConfig.RedisConfiguration.ProcessCheckIntervalSeconds+1)
}
	listener.AcceptTCP()
}

var _ = Describe("waiting for a port to become available", func() {

	var address *net.TCPAddr

	BeforeEach(func() {
		var err error
		address, err = net.ResolveTCPAddr("tcp", "localhost:19000")
		Ω(err).ShouldNot(HaveOccurred())
	})

	Context("when nothing is listening at the specified address", func() {
		It("errors", func() {
			err := availability.Check(address, time.Second*1)
			Ω(err).Should(HaveOccurred())
		})
	})

	Context("when something is already listening at the specified address", func() {
		terminate := make(chan struct{})
		closed := make(chan struct{})

		BeforeEach(func() {
			go func() {
				defer GinkgoRecover()
				listen(*address, 0, terminate, closed)
			}()
		})
Example #4
0
func (portChecker) Check(address *net.TCPAddr, timeout time.Duration) error {
	return availability.Check(address, timeout)
}