<commit_before>package acceptance

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"net/http/httputil"
	"os"
	"os/exec"
	"path/filepath"
	"time"

	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("import-installation command", func() {
	var (
		installation                string
		passphrase                  string
		content                     *os.File
		server                      *httptest.Server
		ensureAvailabilityCallCount int
	)

	BeforeEach(func() {
		var err error
		content, err = ioutil.TempFile("", "cool_name.com")
		Expect(err).NotTo(HaveOccurred())

		_, err = content.WriteString("content so validation does not fail")
		Expect(err).NotTo(HaveOccurred())

		server = httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
			var responseString string
			w.Header().Set("Content-Type", "application/json")

			switch req.URL.Path {
			case "/login/ensure_availability":
				if ensureAvailabilityCallCount < 2 {
					w.Header().Set("Location", "/setup")
					w.WriteHeader(http.StatusFound)
				} else {
					w.Header().Set("Location", "/auth/cloudfoundry")
					w.WriteHeader(http.StatusFound)
				}
				ensureAvailabilityCallCount++
			case "/api/v0/installation_asset_collection":
				err := req.ParseMultipartForm(100)
				Expect(err).NotTo(HaveOccurred())

				installation = req.MultipartForm.File["installation[file]"][0].Filename
				passphrase = req.MultipartForm.Value["passphrase"][0]
				responseString = "{}"
				time.Sleep(2 * time.Second)
			default:
				out, err := httputil.DumpRequest(req, true)
				Expect(err).NotTo(HaveOccurred())
				Fail(fmt.Sprintf("unexpected request: %s", out))
			}<commit_msg>Fix race condition in acceptance test for import-installation<commit_after>package acceptance

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"net/http/httputil"
	"os"
	"os/exec"
	"path/filepath"
	"time"

	"github.com/onsi/gomega/gbytes"
	"github.com/onsi/gomega/gexec"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("import-installation command", func() {
	var (
		installation                string
		passphrase                  string
		content                     *os.File
		server                      *httptest.Server
		ensureAvailabilityCallCount int
	)

	BeforeEach(func() {
		var err error
		content, err = ioutil.TempFile("", "cool_name.com")
		Expect(err).NotTo(HaveOccurred())

		_, err = content.WriteString("content so validation does not fail")
		Expect(err).NotTo(HaveOccurred())

		ensureAvailabilityCallCount = 0

		server = httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
			var responseString string
			w.Header().Set("Content-Type", "application/json")

			switch req.URL.Path {
			case "/login/ensure_availability":
				if ensureAvailabilityCallCount < 2 {
					w.Header().Set("Location", "/setup")
					w.WriteHeader(http.StatusFound)
				} else {
					w.Header().Set("Location", "/auth/cloudfoundry")
					w.WriteHeader(http.StatusFound)
				}
				ensureAvailabilityCallCount++
			case "/api/v0/installation_asset_collection":
				err := req.ParseMultipartForm(100)
				Expect(err).NotTo(HaveOccurred())

				installation = req.MultipartForm.File["installation[file]"][0].Filename
				passphrase = req.MultipartForm.Value["passphrase"][0]
				responseString = "{}"
				time.Sleep(2 * time.Second)
			default:
				out, err := httputil.DumpRequest(req, true)
				Expect(err).NotTo(HaveOccurred())
				Fail(fmt.Sprintf("unexpected request: %s", out))
			}
{'fraction_non_alphanumeric': 0.1400714089535842, 'fraction_numerical': 0.004669046965119473, 'mean_word_length': 3.403869407496977, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, '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': '5613573', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1205, 'n_words': 199}