Beispiel #1
0
func (ctx *serverContext) handlePush(w http.ResponseWriter, r *http.Request) (interface{}, error) {
	pushes, err := strconv.Atoi(r.FormValue("iterations"))
	if err != nil {
		pushes = 1
	}

	concurrency := make([]int, 1)
	concurrency[0], err = strconv.Atoi(r.FormValue("concurrency"))
	if err != nil {
		concurrency[0] = 1
	}

	rawConcurrencyStepTime, err := strconv.Atoi(r.FormValue("concurrency:timeBetweenSteps"))
	concurrencyStepTime := time.Duration(rawConcurrencyStepTime) * time.Second
	if err != nil {
		concurrencyStepTime = 60 * time.Second
	}

	interval, err := strconv.Atoi(r.FormValue("interval"))
	if err != nil {
		interval = 0
	}
	stop, err := strconv.Atoi(r.FormValue("stop"))
	if err != nil {
		stop = 0
	}

	workload := r.FormValue("workload")
	if workload == "" {
		workload = "cf:push"
	}

	workloadContext := context.New()
	workloadContext.PutString("app", r.FormValue("cfApp"))
	workloadContext.PutString("app:manifest", r.FormValue("cfManifest"))
	workloads.PopulateRestContext(r.FormValue("cfTarget"), r.FormValue("cfUsername"), r.FormValue("cfPassword"), r.FormValue("cfSpace"), workloadContext)

	experiment, _ := ctx.lab.Run(
		NewRunnableExperiment(
			NewExperimentConfiguration(
				pushes, concurrency, concurrencyStepTime, interval, stop, ctx.worker, workload)), workloadContext)

	return ctx.router.Get("experiment").URL("name", experiment)
}
Beispiel #2
0
func slaveLoop(conn redis.Conn, delegate Worker, handle string) {
	var redisMsg redisMessage

	logger := logs.NewLogger("redis.slave")
	logger.Info("Started slave")

	for {
		reply, err := redis.Strings(conn.Do("BLPOP", "stop-"+handle, "tasks", 0))

		if len(reply) == 0 {
			panic("Empty task, usually means connection lost, shutting down")
		}

		if reply[0] == "stop-"+handle {
			conn.Do("RPUSH", "stopped-"+handle, true)
			break
		}

		if err == nil {

			redisMsg.WorkloadContext = context.New()

			json.Unmarshal([]byte(reply[1]), &redisMsg)

			go func(experiment string, replyTo string, workloadCtx context.Context) {
				result := delegate.Time(experiment, workloadCtx)
				var encoded []byte
				encoded, err = json.Marshal(result)
				logger.Debug("Completed slave task, replying")
				conn.Do("RPUSH", replyTo, string(encoded))
			}(redisMsg.Workload, redisMsg.Reply, redisMsg.WorkloadContext)
		}

		if err != nil {
			logger.Warnf("ERROR: slave encountered error: %v", err)
		}
	}
}
Beispiel #3
0
)

var workloadContext context.Context

var _ = Describe("Server", func() {
	var (
		lab             *DummyLab
		workloadContext context.Context
	)

	BeforeEach(func() {
		experiments := []*DummyExperiment{&DummyExperiment{"a"}, &DummyExperiment{"b"}, &DummyExperiment{"c"}}
		lab = &DummyLab{}
		lab.experiments = experiments
		http.DefaultServeMux = http.NewServeMux()
		workloadContext = context.New()
	})

	JustBeforeEach(func() {
		ServeWithLab(lab)
	})

	Describe("VCAP_APP_PORT", func() {
		var (
			listen string
			flags  config.Config
		)

		BeforeEach(func() {
			flags = config.NewConfig()
			os.Clearenv()
Beispiel #4
0
package context_test

import (
	"github.com/cloudfoundry-incubator/pat/context"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Context map", func() {

	var (
		localContext context.Context
	)

	JustBeforeEach(func() {
		localContext = context.New()
	})

	Context("String values in context map", func() {
		It("uses a key to identify store fields", func() {
			localContext.PutString("key1", "abc")
			localContext.PutString("key2", "123")

			result, exists := localContext.GetString("key1")
			Ω(result).Should(Equal("abc"))
			Ω(exists).Should(Equal(true))

			result, exists = localContext.GetString("key2")
			Ω(result).Should(Equal("123"))
			Ω(exists).Should(Equal(true))
		})
Beispiel #5
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("RedisWorker", func() {
	var (
		conn        redis.Conn
		workloadCtx context.Context
	)

	BeforeEach(func() {
		StartRedis("../redis/redis.conf")
		var err error
		conn, err = redis.Connect("", 63798, "p4ssw0rd")
		Ω(err).ShouldNot(HaveOccurred())
		workloadCtx = context.New()
	})

	AfterEach(func() {
		StopRedis()
	})

	Describe("When a single experiment is provided", func() {
		Context("When no slaves are running", func() {
			It("Times out after a specified time", func() {
				worker := NewRedisWorkerWithTimeout(conn, 1)
				workloadCtx.PutInt("iterationIndex", 0)
				worker.AddWorkloadStep(workloads.Step("timesout", func() error { time.Sleep(10 * time.Second); return nil }, ""))
				result := make(chan error)
				go func() {
					result <- worker.Time("timesout", workloadCtx).Error
Beispiel #6
0
	JustBeforeEach(func() {
		flags = config.NewConfig()
		InitCommandLineFlags(flags)
		flags.Parse(args)

		BlockExit = func() {}
		err = RunCommandLine()
	})

	Describe("When rest parmaters are supplied", func() {
		var (
			ctx context.Context
		)

		BeforeEach(func() {
			ctx = context.New()
			args = []string{"-rest:target", "someTarget",
				"-rest:username", "someUser",
				"-rest:password", "hunter2",
				"-rest:space", "theFinalFrontier",
			}
			NewContext = func() context.Context {
				return ctx
			}
		})

		It("configures the experiment with the parameter", func() {
			target, ok := ctx.GetString("rest:target")
			Ω(ok).To(BeTrue())
			Ω(target).To(Equal("someTarget"))
Beispiel #7
0
		for i, w := range testList {
			Ω(worker.Workloads[i].Name).Should(Equal(w.Name))
			Ω(worker.Workloads[i].Description).Should(Equal(w.Description))
		}
		Ω(worker.Workloads).Should(HaveLen(4))
	})

	Describe("#PopulateAppContext", func() {
		BeforeEach(func() {
			tmpDir := filepath.Join(os.TempDir(), "patTest")
			os.Chdir(tmpDir)
		})

		It("inserts the app path and manifest path into the context", func() {
			ctx := context.New()
			PopulateAppContext("foo", "manifest.yml", ctx)
			appPath, ok := ctx.GetString("app")
			Ω(Expect(ok).To(BeTrue()))
			Ω(Expect(appPath).To(Equal("foo")))
			manifestPath, ok := ctx.GetString("app:manifest")
			Ω(Expect(ok).To(BeTrue()))
			Ω(Expect(manifestPath).To(Equal("manifest.yml")))
		})

		It("inserts the app path and manifest path into the context", func() {
			ctx := context.New()
			if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
				PopulateAppContext("~/foo", "~/manifest.yml", ctx)

				usr, _ := user.Current()
Beispiel #8
0
package benchmarker

import (
	"time"

	"github.com/cloudfoundry-incubator/pat/context"
	. "github.com/cloudfoundry-incubator/pat/workloads"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Benchmarker", func() {

	workloadCtx := context.New()

	Describe("#Time", func() {
		It("times an arbitrary function", func() {
			time, _ := Time(func() error { time.Sleep(2 * time.Second); return nil })
			Ω(time.Seconds()).Should(BeNumerically("~", 2, 0.5))
		})
	})

	Describe("TimedWithWorker", func() {
		It("sends the timing information retrieved from a worker to a channel", func() {
			ch := make(chan IterationResult)
			result := make(chan time.Duration)
			go func(result chan time.Duration) {
				defer close(ch)
				for t := range ch {
					result <- t.Duration
				}
Beispiel #9
0
}

var LaboratoryFactory = func(store Store) (lab Laboratory) {
	lab = NewLaboratory(store)
	return
}

var BlockExit = func() {
	for {
		in := make([]byte, 1)
		os.Stdin.Read(in)
		if string(in) == "q" {
			return
		}
	}
}

var SilentExit = func(e <-chan int) {
	for _ = range e {
	}
	return
}

var PrintWorkload = func(workload workloads.WorkloadStep) {
	fmt.Printf("\x1b[1m%s\x1b[0m\n\t%s\n", workload.Name, workload.Description)
}

var NewContext = func() context.Context {
	return context.New()
}