예제 #1
1
func runClients(endpoint Endpoint.Endpoint, clients []Client.Client) error {
	// setting up the workers
	in := make(chan Client.Client)
	out := make(chan clientWorkTask)
	worker := func() {
		for client := range in {
			testOutput, err := runClient(client, endpoint)
			out <- clientWorkTask{
				endpoint:   endpoint,
				client:     client,
				err:        err,
				testOutput: testOutput,
			}
		}
	}
	postWork := func() { close(out) }
	Util.Work(len(clients), worker, postWork)

	// starting it up
	go func() {
		for _, client := range clients {
			in <- client
		}
		close(in)
	}()

	// waiting for it to drain out
	var lastError error
	for task := range out {
		if task.err == nil {
			continue
		}

		log.WithFields(log.Fields{
			"endpoint": task.endpoint.Repo.Name,
			"client":   task.client.Repo.Name,
			"err":      task.err.Error(),
		}).Warn("Client run failed")
		lastError = task.err

		if task.testOutput != nil {
			for _, line := range task.testOutput.Results {
				log.WithFields(log.Fields{
					"endpoint": task.endpoint.Repo.Name,
					"client":   task.client.Repo.Name,
					"expected": line.Expected,
					"actual":   line.Actual,
				}).Warn(line.Message)
			}
		}
	}

	return lastError
}
예제 #2
1
// RunEndpoints - runs clients against endpoints
func RunEndpoints(endpoints []Endpoint.Endpoint, resources []Resource.Resource, clients []Client.Client) error {
	// setting up the workers
	in := make(chan Endpoint.Endpoint)
	out := make(chan endpointWorkTask)
	worker := func() {
		for endpoint := range in {
			err := runEndpoint(endpoint, resources, clients)
			out <- endpointWorkTask{
				endpoint: endpoint,
				err:      err,
			}
		}
	}
	postWork := func() { close(out) }
	Util.Work(len(endpoints), worker, postWork)

	// starting it up
	go func() {
		for _, endpoint := range endpoints {
			in <- endpoint
		}
		close(in)
	}()

	// waiting for it to drain out
	var lastError error
	for task := range out {
		if task.err == nil {
			continue
		}

		log.WithFields(log.Fields{
			"endpoint": task.endpoint.Repo.Name,
			"err":      task.err.Error(),
		}).Warn("Endpoint run failed")
		lastError = task.err
	}

	// cleaning the resources
	for _, resource := range resources {
		err := resource.Clean()
		if err == nil {
			continue
		}

		lastError = err
	}

	return lastError
}
예제 #3
1
// NewEndpoints - creates a new list of endpoints
func NewEndpoints(repos []Repo.Repo, resources []Resource.Resource) ([]Endpoint, error) {
	// setting up the workers
	in := make(chan Repo.Repo)
	out := make(chan endpointTask)
	worker := func() {
		for repo := range in {
			endpoint, err := newEndpoint(repo, resources)
			out <- endpointTask{endpoint, err}
		}
	}
	postWork := func() { close(out) }
	Util.Work(len(repos), worker, postWork)

	// starting it up
	go func() {
		for _, repo := range repos {
			in <- repo
		}
		close(in)
	}()

	// waiting for it to drain out
	endpointTasks := []endpointTask{}
	for endpointTask := range out {
		endpointTasks = append(endpointTasks, endpointTask)
	}

	// gathering up the list of endpoints and checking for errors
	endpoints := []Endpoint{}
	for _, endpointTask := range endpointTasks {
		if endpointTask.err != nil {
			return []Endpoint{}, endpointTask.err
		}

		endpoints = append(endpoints, endpointTask.endpoint)
	}

	return endpoints, nil
}
예제 #4
1
// NewRepos - creates a new list of repos from names
func NewRepos(names []string, simpleDocker SimpleDocker.SimpleDocker) ([]Repo, error) {
	// setting up the workers
	in := make(chan string)
	out := make(chan repoTask)
	worker := func() {
		for name := range in {
			repo, err := newRepo(name, simpleDocker)
			out <- repoTask{repo, err}
		}
	}
	postWork := func() { close(out) }
	Util.Work(4, worker, postWork)

	// starting it up
	go func() {
		for _, name := range names {
			in <- name
		}
		close(in)
	}()

	// waiting for it to drain out
	repoTasks := []repoTask{}
	for repoTask := range out {
		repoTasks = append(repoTasks, repoTask)
	}

	// gathering up the list of repos and checking for errors
	repos := []Repo{}
	for _, repoTask := range repoTasks {
		if repoTask.err != nil {
			return []Repo{}, repoTask.err
		}

		repos = append(repos, repoTask.repo)
	}

	return repos, nil
}