Skip to content

Commit

Permalink
run fixtures tests in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Aug 28, 2024
1 parent ac30c0b commit aaf9d27
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 12 deletions.
40 changes: 38 additions & 2 deletions .github/workflows/presubmit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: "Run mock tests"
- name: "Run mock samples tests"
run: |
./scripts/github-actions/tests-e2e-samples
env:
Expand All @@ -91,7 +91,7 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: "Run mock tests"
- name: "Run mock fixtures tests"
run: |
./scripts/github-actions/tests-e2e-fixtures
env:
Expand All @@ -101,6 +101,42 @@ jobs:
with:
name: artifacts
path: /tmp/artifacts/
tests-e2e-fixtures-compute:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: "Run mock fixtures tests for compute service"
run: |
./scripts/github-actions/tests-e2e-fixtures-compute
env:
ARTIFACTS: /tmp/artifacts
- name: "Upload artifacts"
uses: actions/upload-artifact@v3
with:
name: artifacts
path: /tmp/artifacts/
tests-e2e-fixtures-gkehub:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: "Run mock fixtures tests for gkehub service"
run: |
./scripts/github-actions/tests-e2e-fixtures-gkehub
env:
ARTIFACTS: /tmp/artifacts
- name: "Upload artifacts"
uses: actions/upload-artifact@v3
with:
name: artifacts
path: /tmp/artifacts/
pause-tests:
runs-on: ubuntu-22.04
timeout-minutes: 60
Expand Down
2 changes: 2 additions & 0 deletions scripts/github-actions/tests-e2e-fixtures
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-en

echo "Running fixtures in tests/e2e..."

export SKIP_TEST_APIGROUP="compute.cnrm.cloud.google.com,gkehub.cnrm.cloud.google.com"

RUN_E2E=1 \
GOLDEN_OBJECT_CHECKS=1 \
GOLDEN_REQUEST_CHECKS=1 \
Expand Down
35 changes: 35 additions & 0 deletions scripts/github-actions/tests-e2e-fixtures-compute
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

REPO_ROOT="$(git rev-parse --show-toplevel)"

cd ${REPO_ROOT}/

echo "Downloading envtest assets..."
export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path)

echo "Running compute fixtures in tests/e2e..."

RUN_E2E=1 \
GOLDEN_OBJECT_CHECKS=1 \
GOLDEN_REQUEST_CHECKS=1 \
E2E_KUBE_TARGET=envtest \
E2E_GCP_TARGET=mock \
ONLY_TEST_APIGROUP="compute.cnrm.cloud.google.com" \
go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures
35 changes: 35 additions & 0 deletions scripts/github-actions/tests-e2e-fixtures-gkehub
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

REPO_ROOT="$(git rev-parse --show-toplevel)"

cd ${REPO_ROOT}/

echo "Downloading envtest assets..."
export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path)

echo "Running gkehub fixtures in tests/e2e for gkehub..."

RUN_E2E=1 \
GOLDEN_OBJECT_CHECKS=1 \
GOLDEN_REQUEST_CHECKS=1 \
E2E_KUBE_TARGET=envtest \
E2E_GCP_TARGET=mock \
ONLY_TEST_APIGROUP="gkehub.cnrm.cloud.google.com" \
go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures
2 changes: 1 addition & 1 deletion scripts/github-actions/tests-e2e-scenarios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ cd ${REPO_ROOT}/
echo "Downloading envtest assets..."
export KUBEBUILDER_ASSETS=$(go run sigs.k8s.io/controller-runtime/tools/setup-envtest@latest use -p path)

echo "Running scenarios tests for LoggingLogMetric direct reconciliation..."
echo "Running scenarios tests..."
GOLDEN_REQUEST_CHECKS=1 E2E_KUBE_TARGET=envtest E2E_GCP_TARGET=mock RUN_E2E=1 \
go test -test.count=1 -timeout 360s -v ./tests/e2e -run TestE2EScript/scenarios/fields
27 changes: 18 additions & 9 deletions tests/e2e/unified_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"hash/fnv"
"io"
"io/ioutil"
"k8s.io/utils/strings/slices"
"net/http"
"net/url"
"os"
Expand All @@ -31,6 +32,8 @@ import (
"testing"
"time"

"k8s.io/klog/v2"

"github.com/GoogleCloudPlatform/k8s-config-connector/config/tests/samples/create"
opcorev1beta1 "github.com/GoogleCloudPlatform/k8s-config-connector/operator/pkg/apis/core/v1beta1"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test"
Expand Down Expand Up @@ -146,8 +149,21 @@ func testFixturesInSeries(ctx context.Context, t *testing.T, testPause bool, can
fixtures := resourcefixture.Load(t)
for _, fixture := range fixtures {
fixture := fixture
group := fixture.GVK.Group
if s := os.Getenv("SKIP_TEST_APIGROUP"); s != "" {
skippedGroups := strings.Split(s, ",")
if slices.Contains(skippedGroups, group) {
klog.Infof("skipping test %s because group %q matched entries in SKIP_TEST_APIGROUP=%s", fixture.Name, group, s)
continue
}
}
if s := os.Getenv("ONLY_TEST_APIGROUP"); s != "" {
if group != s {
klog.Infof("skipping test %s because group %q did not match ONLY_TEST_APIGROUP=%s", fixture.Name, group, s)
continue
}
}
// TODO(b/259496928): Randomize the resource names for parallel execution when/if needed.

t.Run(fixture.Name, func(t *testing.T) {
ctx := addTestTimeout(ctx, t, subtestTimeout)

Expand Down Expand Up @@ -192,20 +208,13 @@ func runScenario(ctx context.Context, t *testing.T, testPause bool, fixture reso

// Quickly load the fixture with a dummy project, just to see if we should skip it
{
primaryObject, opt := loadFixture(testgcp.GCPProject{ProjectID: "test-skip", ProjectNumber: 123456789}, uniqueID)
_, opt := loadFixture(testgcp.GCPProject{ProjectID: "test-skip", ProjectNumber: 123456789}, uniqueID)
create.MaybeSkip(t, fixture.Name, opt.Create)
if testPause && containsCCOrCCC(opt.Create) {
t.Skipf("test case %q contains ConfigConnector or ConfigConnectorContext object(s): "+
"pause test should not run against test cases already contain ConfigConnector "+
"or ConfigConnectorContext objects", fixture.Name)
}

if s := os.Getenv("ONLY_TEST_APIGROUP"); s != "" {
group := primaryObject.GroupVersionKind().Group
if group != s {
t.Skipf("skipping test because group %q did not match ONLY_TEST_APIGROUP=%s", group, s)
}
}
}

// Create test harness
Expand Down

0 comments on commit aaf9d27

Please sign in to comment.