func startAgent() *gexec.Session {
	config := &agentconfig.Config{
		DefaultConfPath:     helpers.AssetPath("redis.conf.default"),
		ConfPath:            redisConfPath,
		MonitExecutablePath: helpers.AssetPath("fake_monit"),
		Port:                "9876",
		AuthConfiguration: agentconfig.AuthConfiguration{
			Username: "******",
			Password: "******",
		},
	}

	configFile, err := ioutil.TempFile("", "config.yml")
	Expect(err).ToNot(HaveOccurred())

	encoder := candiedyaml.NewEncoder(configFile)
	err = encoder.Encode(config)
	Ω(err).ShouldNot(HaveOccurred())
	configFile.Close()

	agentPath, err := gexec.Build("github.com/pivotal-cf/cf-redis-broker/cmd/agent")
	Ω(err).ShouldNot(HaveOccurred())

	session, err := gexec.Start(
		exec.Command(agentPath, fmt.Sprintf("-agentConfig=%s", configFile.Name())),
		GinkgoWriter,
		GinkgoWriter,
	)
	Ω(err).ShouldNot(HaveOccurred())

	Expect(helpers.ServiceAvailable(9876)).To(BeTrue())
	return session
}
示例#2
0
func startRedis(confPath string) (*gexec.Session, redis.Conn) {
	redisSession, err := gexec.Start(exec.Command("redis-server", confPath), GinkgoWriter, GinkgoWriter)
	Ω(err).ShouldNot(HaveOccurred())

	conf, err := redisconf.Load(confPath)
	Ω(err).ShouldNot(HaveOccurred())

	port, err := strconv.Atoi(conf.Get("port"))
	Ω(err).ShouldNot(HaveOccurred())

	Expect(helpers.ServiceAvailable(uint(port))).To(BeTrue())
	return redisSession, helpers.BuildRedisClient(uint(port), "localhost", conf.Get("requirepass"))
}
func (runner *RedisRunner) Start(redisArgs []string) {
	command := exec.Command("redis-server", redisArgs...)

	var err error
	runner.Dir, err = ioutil.TempDir("", "redis-client-test")
	Ω(err).ShouldNot(HaveOccurred())
	command.Dir = runner.Dir

	err = command.Start()
	Ω(err).ShouldNot(HaveOccurred())

	runner.process = command.Process

	Expect(helpers.ServiceAvailable(RedisPort)).To(BeTrue())
}
示例#4
0
func checkRedisStopAndStart(c chan<- bool) {
	defer GinkgoRecover()

	Eventually(redisSession, "3s").Should(gexec.Exit())

	// Sleep here to emulate the time it takes monit to do it's thing
	time.Sleep(time.Millisecond * 200)

	var err error
	redisSession, err = gexec.Start(exec.Command("redis-server", redisConfPath), GinkgoWriter, GinkgoWriter)
	Ω(err).ShouldNot(HaveOccurred())

	conf, err := redisconf.Load(redisConfPath)
	Ω(err).ShouldNot(HaveOccurred())

	port, err := strconv.Atoi(conf.Get("port"))
	Ω(err).ShouldNot(HaveOccurred())

	Expect(helpers.ServiceAvailable(uint(port))).To(BeTrue())

	c <- true
}
			client = helpers.BuildRedisClient(port, host, password)
		})

		AfterEach(func() {
			helpers.KillProcess(monitorSession)
			client.Close()
			brokerClient.DeprovisionInstance(instanceID)
		})

		It("is restarted", func() {
			_, err := client.Do("SET", "foo", "bar")
			Ω(err).ShouldNot(HaveOccurred())

			helpers.KillRedisProcess(instanceID, brokerConfig)

			Ω(helpers.ServiceAvailable(port)).Should(BeTrue())

			client = helpers.BuildRedisClient(port, host, password)

			value, err := redisclient.String(client.Do("GET", "foo"))
			Ω(err).ToNot(HaveOccurred())
			Ω(value).To(Equal("bar"))
		})

		Context("when there is a lock file for the instance", func() {
			It("is not restarted", func() {
				_, err := client.Do("SET", "foo", "bar")
				Ω(err).ShouldNot(HaveOccurred())

				lockFilePath := filepath.Join(brokerConfig.RedisConfiguration.InstanceDataDirectory, instanceID, "lock")
				lockFile, err := os.Create(lockFilePath)
	"github.com/onsi/ginkgo/reporters"
	. "github.com/onsi/gomega"

	"testing"
)

var redisConfPath string

func TestAgentintegration(t *testing.T) {
	RegisterFailHandler(Fail)
	junitReporter := reporters.NewJUnitReporter("junit_agentintegration.xml")
	RunSpecsWithDefaultAndCustomReporters(t, "Agent Integration Suite", []Reporter{junitReporter})
}

var _ = BeforeSuite(func() {
	if helpers.ServiceAvailable(6379) {
		panic("something is already using the dedicated redis port!")
	}
	dir, err := ioutil.TempDir("", "redisconf-test")
	Expect(err).ToNot(HaveOccurred())
	redisConfPath = filepath.Join(dir, "redis.conf")
})

func startAgent() *gexec.Session {
	config := &agentconfig.Config{
		DefaultConfPath:     helpers.AssetPath("redis.conf.default"),
		ConfPath:            redisConfPath,
		MonitExecutablePath: helpers.AssetPath("fake_monit"),
		Port:                "9876",
		AuthConfiguration: agentconfig.AuthConfiguration{
			Username: "******",
	var instanceID string

	BeforeEach(func() {
		instanceID = uuid.NewRandom().String()
		brokerClient.ProvisionInstance(instanceID, "dedicated")
	})

	AfterEach(func() {
		brokerClient.DeprovisionInstance(instanceID)
	})

	Context("when the broker is restarted", func() {
		BeforeEach(func() {
			helpers.KillProcess(brokerSession)
			brokerSession = integration.LaunchProcessWithBrokerConfig(brokerExecutablePath, "broker.yml")
			Ω(helpers.ServiceAvailable(brokerPort)).Should(BeTrue())
		})

		It("retains state", func() {
			debugInfo := getDebugInfo()

			Ω(debugInfo.Allocated.Count).Should(Equal(1))
			Ω(len(debugInfo.Allocated.Clusters)).Should(Equal(1))

			host := debugInfo.Allocated.Clusters[0].Hosts[0]
			Ω(host).Should(MatchRegexp("server[1-3]\\.127\\.0\\.0\\.1\\.xip\\.io"))

			Ω(debugInfo.Pool.Clusters).ShouldNot(ContainElement([]string{host}))
		})
	})
func switchBroker(config string) {
	helpers.KillProcess(brokerSession)
	helpers.ResetTestDirs()
	brokerSession = integration.LaunchProcessWithBrokerConfig(brokerExecutablePath, config)
	Ω(helpers.ServiceAvailable(brokerPort)).Should(BeTrue())
}
	RunSpecsWithDefaultAndCustomReporters(t, "Broker Integration Suite", []Reporter{junitReporter})
}

var _ = BeforeEach(func() {
	helpers.ResetTestDirs()
})

var _ = BeforeSuite(func() {
	helpers.ResetTestDirs()

	brokerExecutablePath = integration.BuildBroker()
	brokerSession = integration.LaunchProcessWithBrokerConfig(brokerExecutablePath, "broker.yml")

	brokerConfig = integration.LoadBrokerConfig("broker.yml")

	if helpers.ServiceAvailable(uint(brokerConfig.RedisConfiguration.Dedicated.Port)) {
		panic("something is already using the dedicated redis port!")
	}

	brokerClient = &integration.BrokerClient{Config: &brokerConfig}

	Ω(helpers.ServiceAvailable(brokerPort)).Should(BeTrue())
	startFakeAgent(&agentRequests, &agentResponseStatus)
})

var _ = AfterSuite(func() {
	helpers.KillProcess(brokerSession)
})

func getRedisProcessCount() int {
	scriptPath := helpers.AssetPath("redis_process_count.sh")