Exemplo n.º 1
0
import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"time"

	"code.cloudfoundry.org/garden"
	fakes "code.cloudfoundry.org/garden/gardenfakes"
	"code.cloudfoundry.org/garden/server/bomberman"
)

var _ = Describe("Bomberman", func() {
	It("straps a bomb to the given container with the container's grace time as the countdown", func() {
		detonated := make(chan garden.Container)

		backend := new(fakes.FakeBackend)
		backend.GraceTimeReturns(100 * time.Millisecond)

		bomberman := bomberman.New(backend, func(container garden.Container) {
			detonated <- container
		})

		container := new(fakes.FakeContainer)
		container.HandleReturns("doomed")

		bomberman.Strap(container)

		select {
		case <-detonated:
		case <-time.After(backend.GraceTime(container) + 50*time.Millisecond):
			Fail("did not detonate!")
Exemplo n.º 2
0
			apiServer := server.New("tcp", ":60123", 0, new(fakes.FakeBackend), logger)

			err := apiServer.Start()
			Ω(err).ShouldNot(HaveOccurred())

			apiClient = client.New(connection.New("tcp", "127.0.0.1:60123"))
			Eventually(apiClient.Ping).Should(Succeed())
		})
	})

	It("starts the backend", func() {
		var err error
		tmpdir, err = ioutil.TempDir(os.TempDir(), "api-server-test")
		Ω(err).ShouldNot(HaveOccurred())

		fakeBackend := new(fakes.FakeBackend)

		apiServer := server.New(gardenListenNetwork, gardenListenAddr, 0, fakeBackend, logger)

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

		Ω(fakeBackend.StartCallCount()).Should(Equal(1))
	})

	It("destroys containers that have been idle for their grace time", func() {
		var err error
		tmpdir, err = ioutil.TempDir(os.TempDir(), "api-server-test")
		Ω(err).ShouldNot(HaveOccurred())

		fakeBackend := new(fakes.FakeBackend)