<commit_before>package vizzini_test

import (
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"strconv"
	"time"

	. "github.com/pivotal-cf-experimental/vizzini/matchers"

	. "github.com/onsi/gomega"

	"github.com/cloudfoundry-incubator/receptor"
	"github.com/cloudfoundry-incubator/route-emitter/cfroutes"
	"github.com/cloudfoundry-incubator/runtime-schema/models"
)

const HealthyCheckInterval = 30 * time.Second
const ConvergerInterval = 30 * time.Second
const CrashRestartTimeout = 30 * time.Second

//Tasks

func TaskGetter(guid string) func() (receptor.TaskResponse, error) {
	return func() (receptor.TaskResponse, error) {
		return client.GetTask(guid)
	}
}

func TasksByDomainGetter(domain string) func() ([]receptor.TaskResponse, error) {
	return func() ([]receptor.TaskResponse, error) {
		return client.TasksByDomain(domain)
	}
}

func ClearOutTasksInDomain(domain string) {
	tasks, err := client.TasksByDomain(domain)
	Ω(err).ShouldNot(HaveOccurred())
	for _, task := range tasks {
		if task.State != receptor.TaskStateCompleted {
			client.CancelTask(task.TaskGuid)
			Eventually(TaskGetter(task.TaskGuid)).Should(HaveTaskState(receptor.TaskStateCompleted))
		}
		Ω(client.DeleteTask(task.TaskGuid)).Should(Succeed())
	}
	Eventually(TasksByDomainGetter(domain)).Should(BeEmpty())
}

func TaskWithGuid(guid string) receptor.TaskCreateRequest {
	return receptor.TaskCreateRequest{
		TaskGuid: guid,
		Domain:   domain,
		Action: &models.RunAction{
			Path: "bash",
			Args: []string{"-c", "echo 'some output' > /tmp/bar"},
		},
		Stack:      stack,
		MemoryMB:   128,
		DiskMB:     128,
		CPUWeight:  100,
		LogGuid:    guid,
		LogSource:  "VIZ",
		ResultFile: "/tmp/bar",
		Annotation: "arbitrary-data",
	}
}

//LRPs

func LRPGetter(guid string) func() (receptor.DesiredLRPResponse, error) {
	return func() (receptor.DesiredLRPResponse, error) {
		return client.GetDesiredLRP(guid)
	}
}

func ActualGetter(guid string, index int) func() (receptor.ActualLRPResponse, error) {
	return func() (receptor.ActualLRPResponse, error) {
		return client.ActualLRPByProcessGuidAndIndex(guid, index)
	}
}

func ActualByProcessGuidGetter(guid string) func() ([]receptor.ActualLRPResponse, error) {
	return func() ([]receptor.ActualLRPResponse, error) {
		return client.ActualLRPsByProcessGuid(guid)
	}
}

func ActualByDomainGetter(domain string) func() ([]receptor.ActualLRPResponse, error) {
	return func() ([]receptor.ActualLRPResponse, error) {
		return client.ActualLRPsByDomain(domain)
	}
}

func ClearOutDesiredLRPsInDomain(domain string) {
	lrps, err := client.DesiredLRPsByDomain(domain)
	Ω(err).ShouldNot(HaveOccurred())
	for _, lrp := range lrps {
		Ω(client.DeleteDesiredLRP(lrp.ProcessGuid)).Should(Succeed())
	}
	Eventually(ActualByDomainGetter(domain)).Should(BeEmpty())
}

func EndpointCurler(endpoint string) func() (int, error) {
	return func() (int, error) {
		resp, err := http.Get(endpoint)<commit_msg>Increase timeout to allow 10s kill timeout<commit_after>package vizzini_test

import (
	"errors"
	"fmt"
	"io/ioutil"
	"net/http"
	"strconv"
	"time"

	. "github.com/pivotal-cf-experimental/vizzini/matchers"

	. "github.com/onsi/gomega"

	"github.com/cloudfoundry-incubator/receptor"
	"github.com/cloudfoundry-incubator/route-emitter/cfroutes"
	"github.com/cloudfoundry-incubator/runtime-schema/models"
)

const HealthyCheckInterval = 30 * time.Second
const ConvergerInterval = 30 * time.Second
const CrashRestartTimeout = 30 * time.Second

//Tasks

func TaskGetter(guid string) func() (receptor.TaskResponse, error) {
	return func() (receptor.TaskResponse, error) {
		return client.GetTask(guid)
	}
}

func TasksByDomainGetter(domain string) func() ([]receptor.TaskResponse, error) {
	return func() ([]receptor.TaskResponse, error) {
		return client.TasksByDomain(domain)
	}
}

func ClearOutTasksInDomain(domain string) {
	tasks, err := client.TasksByDomain(domain)
	Ω(err).ShouldNot(HaveOccurred())
	for _, task := range tasks {
		if task.State != receptor.TaskStateCompleted {
			client.CancelTask(task.TaskGuid)
			Eventually(TaskGetter(task.TaskGuid)).Should(HaveTaskState(receptor.TaskStateCompleted))
		}
		Ω(client.DeleteTask(task.TaskGuid)).Should(Succeed())
	}
	Eventually(TasksByDomainGetter(domain)).Should(BeEmpty())
}

func TaskWithGuid(guid string) receptor.TaskCreateRequest {
	return receptor.TaskCreateRequest{
		TaskGuid: guid,
		Domain:   domain,
		Action: &models.RunAction{
			Path: "bash",
			Args: []string{"-c", "echo 'some output' > /tmp/bar"},
		},
		Stack:      stack,
		MemoryMB:   128,
		DiskMB:     128,
		CPUWeight:  100,
		LogGuid:    guid,
		LogSource:  "VIZ",
		ResultFile: "/tmp/bar",
		Annotation: "arbitrary-data",
	}
}

//LRPs

func LRPGetter(guid string) func() (receptor.DesiredLRPResponse, error) {
	return func() (receptor.DesiredLRPResponse, error) {
		return client.GetDesiredLRP(guid)
	}
}

func ActualGetter(guid string, index int) func() (receptor.ActualLRPResponse, error) {
	return func() (receptor.ActualLRPResponse, error) {
		return client.ActualLRPByProcessGuidAndIndex(guid, index)
	}
}

func ActualByProcessGuidGetter(guid string) func() ([]receptor.ActualLRPResponse, error) {
	return func() ([]receptor.ActualLRPResponse, error) {
		return client.ActualLRPsByProcessGuid(guid)
	}
}

func ActualByDomainGetter(domain string) func() ([]receptor.ActualLRPResponse, error) {
	return func() ([]receptor.ActualLRPResponse, error) {
		return client.ActualLRPsByDomain(domain)
	}
}

func ClearOutDesiredLRPsInDomain(domain string) {
	lrps, err := client.DesiredLRPsByDomain(domain)
	Ω(err).ShouldNot(HaveOccurred())
	for _, lrp := range lrps {
		Ω(client.DeleteDesiredLRP(lrp.ProcessGuid)).Should(Succeed())
	}
	Eventually(ActualByDomainGetter(domain), 15).Should(BeEmpty())
}

func EndpointCurler(endpoint string) func() (int, error) {
	return func() (int, error) {
		resp, err := http.Get(endpoint)
{'fraction_non_alphanumeric': 0.1359372334982091, 'fraction_numerical': 0.005799078969810677, 'mean_word_length': 5.415754923413567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4069031', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2049, 'n_words': 372}