コード例 #1
0
ファイル: server.go プロジェクト: nkts/golang-devops-stuff
func (s *WardenServer) Start() error {
	err := s.removeExistingSocket()
	if err != nil {
		return err
	}

	err = s.backend.Start()
	if err != nil {
		return err
	}

	listener, err := net.Listen(s.listenNetwork, s.listenAddr)
	if err != nil {
		return err
	}

	s.listener = listener

	if s.listenNetwork == "unix" {
		os.Chmod(s.listenAddr, 0777)
	}

	containers, err := s.backend.Containers()
	if err != nil {
		return err
	}

	s.bomberman = bomberman.New(s.reapContainer)

	for _, container := range containers {
		s.bomberman.Strap(container)
	}

	go s.trackStopping()
	go s.handleConnections(listener)

	return nil
}
コード例 #2
0
import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"github.com/pivotal-cf-experimental/garden/backend"
	"github.com/pivotal-cf-experimental/garden/backend/fake_backend"
	"github.com/pivotal-cf-experimental/garden/server/bomberman"
	"time"
)

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 backend.Container)

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

		container := fake_backend.NewFakeContainer(
			backend.ContainerSpec{
				GraceTime: 100 * time.Millisecond,
				Handle:    "doomed",
			},
		)

		bomberman.Strap(container)

		select {
		case <-detonated:
		case <-time.After(container.GraceTime() + 50*time.Millisecond):
			Fail("did not detonate!")