Beispiel #1
0
// define testcases using teststeps
func tc1(m *gogrinder.Meta, s gogrinder.Settings) {
	var mm *req.HttpMetric
	c := req.NewDefaultClient()
	form := url.Values{}
	form.Add("username", "gogrinder")

	b := gg.NewBracket("01_01_login")
	{
		r, err := http.NewRequest("POST", "http://localhost:3001/login",
			strings.NewReader(form.Encode()))
		r.Header.Add("Content-Type", "application/x-www-form-urlencoded")
		if err != nil {
			m.Error += err.Error()
			mm = &req.HttpMetric{*m, 0, 0, 400}
		}
		_, _, mm = req.DoRaw(c, r, m)
	}
	b.End(mm)

	b = gg.NewBracket("01_02_get")
	{
		r, err := http.NewRequest("GET", "http://localhost:3001/get_private", nil)
		if err != nil {
			m.Error += err.Error()
			mm = &req.HttpMetric{*m, 0, 0, 400}
		}
		_, _, mm = req.DoRaw(c, r, m)
	}
	b.End(mm)
}
Beispiel #2
0
func supercars_05_delete(m *gogrinder.Meta, s gogrinder.Settings) {
	var mm *req.HttpMetric
	c := req.NewDefaultClient()
	base := s["supercars_url"].(string)

	b := gg.NewBracket("05_01_supercars_delete")
	redis, err := goredis.Dial(&goredis.DialConfig{Address: s["redis_srv"].(string)})
	if err != nil {
		// is the redis server running? correct address?
		m.Error += err.Error()
		return
	}

	id, err := redis.SPop("supercars")
	if err != nil {
		// probably run out of data - so it does not make sense to continue
		m.Error += err.Error()
		return
	}
	r, err := http.NewRequest("DELETE", base+"/rest/supercars/"+string(id), nil)
	if err != nil {
		m.Error += err.Error()
		mm = &req.HttpMetric{*m, 0, 0, 400}
	} else {
		_, _, mm = req.DoRaw(c, r, m)
	}
	b.End(mm)
}
Beispiel #3
0
func main() {
	// note: this test script is structured differently so the testcase can have
	// access to the main scope
	rec := []<-chan string{
		util.XmlReader("bang_0.xml", "record"), util.XmlReader("bang_1.xml", "record")}

	// initialize the GoGrinder
	gg := gogrinder.NewTest()

	// define testcases using teststeps
	xmlcowboys_01_post := func(m *gogrinder.Meta, s gogrinder.Settings) {
		var mm *req.HttpMetric
		c := req.NewDefaultClient()
		r := rec[m.User]
		str := <-r
		//fmt.Println(str)
		base := s["server_url"].(string)
		b := gg.NewBracket("01_01_xmlcowboys_post")
		{
			r, err := http.NewRequest("POST", base+"/post_stuff",
				strings.NewReader(str))
			if err != nil {
				m.Error += err.Error()
				mm = &req.HttpMetric{*m, 0, 0, 400}
			}
			_, _, mm = req.DoRaw(c, r, m)
		}
		b.End(mm)

	}

	// this is my endurance test scenario
	endurance := func() {
		// use the tests with the loadmodel config (json file)
		gg.Schedule("xmlcowboys_01_post", xmlcowboys_01_post)
	}

	// this is my baseline test scenario
	baseline := func() {
		// use the tests with a explicit configuration
		gg.DoIterations(xmlcowboys_01_post, 5, 0, false)
	}

	// register the scenarios defined above
	gg.Testscenario("endurance", endurance)
	gg.Testscenario("baseline", baseline)
	// register the testcases as scenarios to allow single execution mode
	gg.Testscenario("xmlcowboys_01_post", xmlcowboys_01_post)

	gg.AddReportPlugin(req.NewHttpMetricReporter())
	err := gogrinder.GoGrinder(gg)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
}
Beispiel #4
0
// define testcases using teststeps
func tc1(m *gogrinder.Meta, s gogrinder.Settings) {
	var mm *req.HttpMetric
	c := req.NewDefaultClient()

	b := gg.NewBracket("01_01_teststep")
	{
		r, err := http.NewRequest("GET", "http://localhost:3001/get_stuff", nil)
		if err != nil {
			m.Error += err.Error()
			mm = &req.HttpMetric{*m, 0, 0, 400}
		}
		_, _, mm = req.DoRaw(c, r, m)
	}
	b.End(mm)
}
Beispiel #5
0
func tc2(m *gogrinder.Meta, s gogrinder.Settings) {
	var mm *req.HttpMetric
	c := req.NewDefaultClient()

	b := gg.NewBracket("02_01_post")
	{
		r, err := http.NewRequest("POST", "http://localhost:3001/post_stuff",
			util.NewRandReader(2000))
		if err != nil {
			m.Error += err.Error()
			mm = &req.HttpMetric{*m, 0, 0, 400}
		}
		_, _, mm = req.DoRaw(c, r, m)
	}
	b.End(mm)
}