Skip to content

Run functional and NFR tests with --race #3614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ stop-longevity-test: nfr-test ## Stop the longevity test and collects results

.PHONY: .vm-nfr-test
.vm-nfr-test: ## Runs the NFR tests on the GCP VM (called by `nfr-test`)
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --keep-going --fail-on-pending \
--trace -r -v --buildvcs --force-newlines $(GITHUB_OUTPUT) \
CGO_ENABLED=1 go run github.com/onsi/ginkgo/v2/ginkgo --race --randomize-all --randomize-suites --keep-going --fail-on-pending \
--trace -r -v --buildvcs --force-newlines $(GITHUB_OUTPUT) --flake-attempts=2 \
--label-filter "nfr" $(GINKGO_FLAGS) --timeout 5h ./suite -- --gateway-api-version=$(GW_API_VERSION) \
--gateway-api-prev-version=$(GW_API_PREV_VERSION) --image-tag=$(TAG) --version-under-test=$(NGF_VERSION) \
--ngf-image-repo=$(PREFIX) --nginx-image-repo=$(NGINX_PREFIX) --nginx-plus-image-repo=$(NGINX_PLUS_PREFIX) \
Expand All @@ -132,7 +132,7 @@ stop-longevity-test: nfr-test ## Stop the longevity test and collects results
.PHONY: test
test: build-crossplane-image ## Runs the functional tests on your kind k8s cluster
kind load docker-image nginx-crossplane:latest --name $(CLUSTER_NAME)
go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --keep-going --fail-on-pending \
go run github.com/onsi/ginkgo/v2/ginkgo --race --randomize-all --randomize-suites --keep-going --fail-on-pending \
--trace -r -v --buildvcs --force-newlines $(GITHUB_OUTPUT) \
--label-filter "functional" $(GINKGO_FLAGS) ./suite -- \
--gateway-api-version=$(GW_API_VERSION) --gateway-api-prev-version=$(GW_API_PREV_VERSION) \
Expand Down
33 changes: 30 additions & 3 deletions tests/framework/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"path"
"sync"
"time"

"k8s.io/client-go/rest"
Expand Down Expand Up @@ -35,12 +36,10 @@ func PortForward(config *rest.Config, namespace, podName string, ports []string,

dialer := spdy.NewDialer(upgrader, &http.Client{Transport: roundTripper}, http.MethodPost, serverURL)

out, errOut := new(bytes.Buffer), new(bytes.Buffer)

forward := func() error {
readyCh := make(chan struct{}, 1)

forwarder, err := portforward.New(dialer, ports, stopCh, readyCh, out, errOut)
forwarder, err := portforward.New(dialer, ports, stopCh, readyCh, newSafeBuffer(), newSafeBuffer())
if err != nil {
return fmt.Errorf("error creating port forwarder: %w", err)
}
Expand All @@ -66,3 +65,31 @@ func PortForward(config *rest.Config, namespace, podName string, ports []string,

return nil
}

// safeBuffer is a goroutine safe bytes.Buffer.
type safeBuffer struct {
buffer bytes.Buffer
mutex sync.Mutex
}

func newSafeBuffer() *safeBuffer {
return &safeBuffer{}
}

// Write appends the contents of p to the buffer, growing the buffer as needed. It returns
// the number of bytes written.
func (s *safeBuffer) Write(p []byte) (n int, err error) {
s.mutex.Lock()
defer s.mutex.Unlock()

return s.buffer.Write(p)
}

// String returns the contents of the unread portion of the buffer
// as a string. If the Buffer is a nil pointer, it returns "<nil>".
func (s *safeBuffer) String() string {
s.mutex.Lock()
defer s.mutex.Unlock()

return s.buffer.String()
}
15 changes: 4 additions & 11 deletions tests/framework/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func makeRequest(
return nil, errors.New("transport is not of type *http.Transport")
}

transport.DialContext = func(
customTransport := transport.Clone()
customTransport.DialContext = func(
ctx context.Context,
network,
addr string,
Expand Down Expand Up @@ -93,21 +94,13 @@ func makeRequest(

var resp *http.Response
if strings.HasPrefix(url, "https") {
transport, ok := http.DefaultTransport.(*http.Transport)
if !ok {
return nil, errors.New("transport is not of type *http.Transport")
}

customTransport := transport.Clone()
// similar to how in our examples with https requests we run our curl command
// we turn off verification of the certificate, we do the same here
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} //nolint:gosec // for https test traffic
client := &http.Client{Transport: customTransport}
resp, err = client.Do(req)
} else {
resp, err = http.DefaultClient.Do(req)
}

client := &http.Client{Transport: customTransport}
resp, err = client.Do(req)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions tests/scripts/create-and-setup-gcp-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ done

gcloud compute scp --zone "${GKE_CLUSTER_ZONE}" --project="${GKE_PROJECT}" "${SCRIPT_DIR}"/vars.env username@"${RESOURCE_NAME}":~

gcloud compute ssh --zone "${GKE_CLUSTER_ZONE}" --project="${GKE_PROJECT}" username@"${RESOURCE_NAME}" --command="bash -s" <"${SCRIPT_DIR}"/remote-scripts/install-deps.sh

if [ -n "${NGF_REPO}" ] && [ "${NGF_REPO}" != "nginx" ]; then
gcloud compute ssh --zone "${GKE_CLUSTER_ZONE}" --project="${GKE_PROJECT}" username@"${RESOURCE_NAME}" \
--command="bash -i <<EOF
Expand Down
7 changes: 7 additions & 0 deletions tests/scripts/remote-scripts/install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e

source ~/vars.env

sudo apt-get -y update && sudo apt-get -y install gcc
Loading