Skip to content

Commit ce0c5f4

Browse files
authored
refactor: E2E tests to support parallel tests (#2501)
1 parent 77b8210 commit ce0c5f4

23 files changed

+1111
-874
lines changed

.github/workflows/apisix-e2e-test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ jobs:
7373
with:
7474
go-version: "1.23"
7575

76+
- name: Install ginkgo
77+
run: |
78+
make install-ginkgo
79+
7680
- name: Build images
7781
env:
7882
TAG: dev
@@ -111,4 +115,4 @@ jobs:
111115
PROVIDER_TYPE: ${{ matrix.provider_type }}
112116
TEST_LABEL: ${{ matrix.cases_subset }}
113117
run: |
114-
make e2e-test
118+
make ginkgo-e2e-test

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ADC_VERSION ?= 0.20.0
3333
GINKGO_VERSION ?= 2.20.0
3434
TEST_TIMEOUT ?= 80m
3535
TEST_DIR ?= ./test/e2e/apisix/
36-
E2E_NODES ?= 2
36+
E2E_NODES ?= 4
3737

3838
# CRD Reference Documentation
3939
CRD_REF_DOCS_VERSION ?= v0.1.0
@@ -131,7 +131,7 @@ e2e-test:
131131

132132
.PHONY: ginkgo-e2e-test
133133
ginkgo-e2e-test:
134-
@ginkgo -cover -coverprofile=coverage.txt -r --randomize-all --randomize-suites --trace --focus=$(E2E_FOCUS) --nodes=$(E2E_NODES) $(TEST_DIR)
134+
@ginkgo -cover -coverprofile=coverage.txt -r --randomize-all --randomize-suites --trace --focus=$(E2E_FOCUS) --nodes=$(E2E_NODES) --label-filter="$(TEST_LABEL)" $(TEST_DIR)
135135

136136
.PHONY: install-ginkgo
137137
install-ginkgo:

test/e2e/crds/v1alpha1/backendtrafficpolicy.go

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,28 @@ package v1alpha1
1919

2020
import (
2121
"fmt"
22+
"time"
2223

2324
. "github.com/onsi/ginkgo/v2"
2425
. "github.com/onsi/gomega"
26+
"k8s.io/apimachinery/pkg/types"
2527

2628
"github.com/apache/apisix-ingress-controller/test/e2e/scaffold"
2729
)
2830

2931
var _ = Describe("Test BackendTrafficPolicy base on HTTPRoute", Label("apisix.apache.org", "v1alpha1", "backendtrafficpolicy"), func() {
30-
s := scaffold.NewDefaultScaffold()
32+
var (
33+
s = scaffold.NewScaffold(&scaffold.Options{
34+
ControllerName: fmt.Sprintf("apisix.apache.org/apisix-ingress-controller-%d", time.Now().Unix()),
35+
})
36+
err error
37+
)
3138

3239
var defaultGatewayProxy = `
3340
apiVersion: apisix.apache.org/v1alpha1
3441
kind: GatewayProxy
3542
metadata:
36-
name: apisix-proxy-config
43+
name: %s
3744
spec:
3845
provider:
3946
type: ControlPlane
@@ -59,7 +66,7 @@ spec:
5966
apiVersion: gateway.networking.k8s.io/v1
6067
kind: Gateway
6168
metadata:
62-
name: apisix
69+
name: %s
6370
spec:
6471
gatewayClassName: %s
6572
listeners:
@@ -70,17 +77,18 @@ spec:
7077
parametersRef:
7178
group: apisix.apache.org
7279
kind: GatewayProxy
73-
name: apisix-proxy-config
80+
name: %s
7481
`
7582

7683
var defaultHTTPRoute = `
7784
apiVersion: gateway.networking.k8s.io/v1
7885
kind: HTTPRoute
7986
metadata:
8087
name: httpbin
88+
namespace: %s
8189
spec:
8290
parentRefs:
83-
- name: apisix
91+
- name: %s
8492
hostnames:
8593
- "httpbin.org"
8694
rules:
@@ -125,7 +133,26 @@ spec:
125133
`
126134

127135
BeforeEach(func() {
128-
s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute)
136+
gatewayName := s.Namespace()
137+
By("create GatewayProxy")
138+
gatewayProxyName := gatewayName
139+
err = s.CreateResourceFromString(fmt.Sprintf(defaultGatewayProxy, gatewayProxyName, s.Deployer.GetAdminEndpoint(), s.AdminKey()))
140+
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
141+
time.Sleep(time.Second)
142+
143+
By("create GatewayClass")
144+
gatewayClassName := fmt.Sprintf("apisix-%d", time.Now().Unix())
145+
err = s.CreateResourceFromString(fmt.Sprintf(defaultGatewayClass, gatewayClassName, s.GetControllerName()))
146+
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
147+
time.Sleep(time.Second)
148+
149+
By("create Gateway")
150+
err = s.CreateResourceFromString(fmt.Sprintf(defaultGateway, gatewayName, gatewayClassName, gatewayProxyName))
151+
Expect(err).NotTo(HaveOccurred(), "creating Gateway")
152+
time.Sleep(time.Second)
153+
154+
By("create HTTPRoute")
155+
s.ApplyHTTPRoute(types.NamespacedName{Namespace: s.Namespace(), Name: "httpbin"}, fmt.Sprintf(defaultHTTPRoute, gatewayName, s.Namespace()))
129156
})
130157
It("should rewrite upstream host", func() {
131158
s.ResourceApplied("BackendTrafficPolicy", "httpbin", createUpstreamHost, 1)
@@ -184,15 +211,14 @@ spec:
184211

185212
var _ = Describe("Test BackendTrafficPolicy base on Ingress", Label("apisix.apache.org", "v1alpha1", "backendtrafficpolicy"), func() {
186213
s := scaffold.NewScaffold(&scaffold.Options{
187-
ControllerName: "apisix.apache.org/apisix-ingress-controller",
214+
ControllerName: fmt.Sprintf("apisix.apache.org/apisix-ingress-controller-%d", time.Now().Unix()),
188215
})
189216

190217
var defaultGatewayProxy = `
191218
apiVersion: apisix.apache.org/v1alpha1
192219
kind: GatewayProxy
193220
metadata:
194-
name: apisix-proxy-config
195-
namespace: default
221+
name: %s
196222
spec:
197223
provider:
198224
type: ControlPlane
@@ -212,12 +238,12 @@ metadata:
212238
annotations:
213239
ingressclass.kubernetes.io/is-default-class: "true"
214240
spec:
215-
controller: "apisix.apache.org/apisix-ingress-controller"
241+
controller: "%s"
216242
parameters:
217243
apiGroup: "apisix.apache.org"
218244
kind: "GatewayProxy"
219-
name: "apisix-proxy-config"
220-
namespace: "default"
245+
name: "%s"
246+
namespace: "%s"
221247
scope: "Namespace"
222248
`
223249

@@ -241,25 +267,28 @@ spec:
241267
`
242268
var beforeEach = func() {
243269
By("create GatewayProxy")
244-
gatewayProxy := fmt.Sprintf(defaultGatewayProxy, s.Deployer.GetAdminEndpoint(), s.AdminKey())
245-
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default")
270+
gatewayProxyName := s.Namespace()
271+
gatewayProxy := fmt.Sprintf(defaultGatewayProxy, gatewayProxyName, s.Deployer.GetAdminEndpoint(), s.AdminKey())
272+
err := s.CreateResourceFromString(gatewayProxy)
246273
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
247274

248275
By("create IngressClass with GatewayProxy reference")
249-
err = s.CreateResourceFromStringWithNamespace(defaultIngressClass, "")
276+
err = s.CreateResourceFromString(fmt.Sprintf(defaultIngressClass, s.GetControllerName(), gatewayProxyName, s.Namespace()))
250277
Expect(err).NotTo(HaveOccurred(), "creating IngressClass with GatewayProxy")
251278

252279
By("create Ingress with GatewayProxy IngressClass")
253280
err = s.CreateResourceFromString(defaultIngress)
254281
Expect(err).NotTo(HaveOccurred(), "creating Ingress with GatewayProxy IngressClass")
255282
}
256283

257-
Context("Rewrite Upstream Host", func() {
284+
// Tests concerning the default ingress class need to be run serially
285+
Context("Rewrite Upstream Host", Serial, func() {
258286
var createUpstreamHost = `
259287
apiVersion: apisix.apache.org/v1alpha1
260288
kind: BackendTrafficPolicy
261289
metadata:
262290
name: httpbin
291+
namespace: %s
263292
spec:
264293
targetRefs:
265294
- name: httpbin-service-e2e-test
@@ -274,6 +303,7 @@ apiVersion: apisix.apache.org/v1alpha1
274303
kind: BackendTrafficPolicy
275304
metadata:
276305
name: httpbin
306+
namespace: %s
277307
spec:
278308
targetRefs:
279309
- name: httpbin-service-e2e-test
@@ -293,19 +323,20 @@ spec:
293323
"Host": "httpbin.org",
294324
},
295325
}
296-
s.ResourceApplied("BackendTrafficPolicy", "httpbin", createUpstreamHost, 1)
326+
327+
s.ResourceApplied("BackendTrafficPolicy", "httpbin", fmt.Sprintf(createUpstreamHost, s.Namespace()), 1)
297328
s.RequestAssert(reqAssert.SetChecks(
298329
scaffold.WithExpectedStatus(200),
299330
scaffold.WithExpectedBodyContains("httpbin.example.com"),
300331
))
301332

302-
s.ResourceApplied("BackendTrafficPolicy", "httpbin", updateUpstreamHost, 2)
333+
s.ResourceApplied("BackendTrafficPolicy", "httpbin", fmt.Sprintf(updateUpstreamHost, s.Namespace()), 2)
303334
s.RequestAssert(reqAssert.SetChecks(
304335
scaffold.WithExpectedStatus(200),
305336
scaffold.WithExpectedBodyContains("httpbin.update.example.com"),
306337
))
307338

308-
err := s.DeleteResourceFromString(createUpstreamHost)
339+
err := s.DeleteResourceFromString(fmt.Sprintf(createUpstreamHost, s.Namespace()))
309340
Expect(err).NotTo(HaveOccurred(), "deleting BackendTrafficPolicy")
310341

311342
s.RequestAssert(reqAssert.SetChecks(

0 commit comments

Comments
 (0)