Esempio n. 1
0
File: task.go Progetto: pquerna/hurl
func NewTask(ui common.UI) (workers.WorkerTask, error) {
	c := ui.ConfigGet()
	conf := c.GetSwiftConfig()
	if conf == nil {
		panic("Invalid Configuration object for swift worker")
	}

	conn := swift.Connection{
		UserName: conf.Username,
		ApiKey:   conf.ApiKey,
		AuthUrl:  conf.AuthUrl,
		// https://auth.api.rackspacecloud.com/v1.0
		Region:    conf.Region,
		UserAgent: fmt.Sprintf("hurl/1 http load tester; https://github.com/pquerna/hurl;  username=%s", conf.Username),
	}

	if authTokenCache != "" && storageUrlCache != "" {
		conn.AuthToken = authTokenCache
		conn.StorageUrl = storageUrlCache
	} else {
		err := conn.Authenticate()
		if err != nil {
			return nil, err
		}
		authTokenCache = conn.AuthToken
		storageUrlCache = conn.StorageUrl
	}

	return &Task{
		conf: conf,
		conn: &conn}, nil
}
Esempio n. 2
0
File: task.go Progetto: pquerna/hurl
func NewTask(ui common.UI) (workers.WorkerTask, error) {
	c := ui.ConfigGet()
	conf := c.GetHttpConfig()
	if conf == nil {
		panic("Invalid Configuration object for http/1 worker")
	}

	// TODO(pquerna): TLS transport configuration
	trans := &nhttp.Transport{
		/* TODO: conf.Compression */
		DisableCompression:  true,
		DisableKeepAlives:   !conf.Keepalive,
		MaxIdleConnsPerHost: conf.Concurrency,
	}
	//	client := &nhttp.Client{
	//		Transport: trans,
	//		CheckRedirect: func(req *nhttp.Request, via []*nhttp.Request) error {
	//			return errors.New("do not follow redirects")
	//		},
	//	}

	url, err := url.Parse(conf.Url)
	if err != nil {
		panic("Broken URL")
	}

	return &Task{conf: conf, transport: trans, URL: url}, nil
}
Esempio n. 3
0
File: task.go Progetto: pquerna/hurl
func NewTask(ui common.UI) (workers.WorkerTask, error) {
	c := ui.ConfigGet()
	conf := c.GetEtcdConfig()
	if conf == nil {
		panic("Invalid Configuration object for etcd worker")
	}

	client := etcd.NewClient([]string{conf.Url})

	return &Task{conf: conf, client: client}, nil
}
Esempio n. 4
0
func Run(ui common.UI, taskType string) error {
	//	if clusterConf != "" {
	//		// TODO: add ClusterWorker
	//		return nil, fmt.Errorf("TODO: Cluster support")
	//	}
	wt, ok := g_workers_tasks[taskType]
	if !ok {
		return fmt.Errorf("unknown worker type: %s", taskType)
	}

	conf := ui.ConfigGet()
	bconf := conf.GetBasicConfig()
	workers := make([]Worker, bconf.Concurrency)
	for index, _ := range workers {
		w, err := wt(ui)
		if err != nil {
			return err
		}
		workers[index] = &LocalWorker{task: w}
	}

	ui.WorkStart(bconf.NumRequests)
	defer func() {
		for _, worker := range workers {
			worker.Halt()
		}
	}()

	var wg sync.WaitGroup
	var wgres sync.WaitGroup
	reqchan := make(chan int64, 1024*1024)
	// TODO: how big should this be?
	reschan := make(chan *common.Result)
	for _, worker := range workers {
		err := worker.Start(taskType, &wg, reqchan, reschan)
		if err != nil {
			return err
		}
	}

	var i int64

	for i = 0; i < bconf.NumRequests; i++ {
		reqchan <- i
		// TOOD: ui.WorkStatus(numDone int64)
	}
	wgres.Add(1)

	rw := common.NewResultArchiveWriter()
	defer rw.Remove()
	go resultHanlder(ui, &wgres, reschan, rw)

	close(reqchan)
	wg.Wait()
	close(reschan)
	wgres.Wait()
	ui.WorkEnd()

	rw.Close()

	rr := common.NewResultArchiveReader(rw.Path)
	return reports.Run(ui, taskType, conf, rr)
}