Skip to content

Commit 781a2f7

Browse files
authored
test(e2e): parallelise test execution (#94)
Signed-off-by: Francesco Canovai <[email protected]>
1 parent 9ed845c commit 781a2f7

File tree

5 files changed

+63
-44
lines changed

5 files changed

+63
-44
lines changed

Taskfile.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,17 @@ tasks:
204204
deps:
205205
- build-images
206206
cmds:
207-
- go test -timeout 60m -v ./test/e2e
207+
- >
208+
go run github.com/onsi/ginkgo/v2/ginkgo
209+
--procs=8
210+
--randomize-all
211+
--randomize-suites
212+
--fail-on-pending
213+
--fail-on-empty
214+
--keep-going
215+
--timeout=30m
216+
--github-output
217+
./test/e2e
208218
209219
ci:
210220
desc: Run the CI pipeline

test/e2e/e2e_suite_test.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,12 @@ import (
2222
"testing"
2323
"time"
2424

25-
certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
26-
cloudnativepgv1 "github.com/cloudnative-pg/api/pkg/api/v1"
27-
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
28-
appsv1 "k8s.io/api/apps/v1"
29-
corev1 "k8s.io/api/core/v1"
30-
rbacv1 "k8s.io/api/rbac/v1"
31-
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
3225
apimachineryTypes "k8s.io/apimachinery/pkg/types"
3326
"k8s.io/apimachinery/pkg/util/wait"
3427
"sigs.k8s.io/controller-runtime/pkg/client"
3528
kustomizeTypes "sigs.k8s.io/kustomize/api/types"
3629
"sigs.k8s.io/kustomize/kyaml/resid"
3730

38-
pluginBarmanCloudV1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
3931
"github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/deployment"
4032
"github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/e2etestenv"
4133
"github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/kustomize"
@@ -96,32 +88,6 @@ var _ = SynchronizedBeforeSuite(func(ctx SpecContext) []byte {
9688
},
9789
}
9890

99-
scheme := cl.Scheme()
100-
if err := corev1.AddToScheme(scheme); err != nil {
101-
Fail(fmt.Sprintf("failed to add core/v1 to scheme: %v", err))
102-
}
103-
if err := apiextensionsv1.AddToScheme(scheme); err != nil {
104-
Fail(fmt.Sprintf("failed to add apiextensions/v1 to scheme: %v", err))
105-
}
106-
if err := admissionregistrationv1.AddToScheme(scheme); err != nil {
107-
Fail(fmt.Sprintf("failed to add admissionregistration/v1 to scheme: %v", err))
108-
}
109-
if err := rbacv1.AddToScheme(scheme); err != nil {
110-
Fail(fmt.Sprintf("failed to add rbac/v1 to scheme: %v", err))
111-
}
112-
if err := appsv1.AddToScheme(scheme); err != nil {
113-
Fail(fmt.Sprintf("failed to add apps/v1 to scheme: %v", err))
114-
}
115-
if err := certmanagerv1.AddToScheme(scheme); err != nil {
116-
Fail(fmt.Sprintf("failed to add cert-manager.io/v1 to scheme: %v", err))
117-
}
118-
if err := pluginBarmanCloudV1.AddToScheme(scheme); err != nil {
119-
Fail(fmt.Sprintf("failed to add plugin-barman-cloud/v1 to scheme: %v", err))
120-
}
121-
if err := cloudnativepgv1.AddToScheme(scheme); err != nil {
122-
Fail(fmt.Sprintf("failed to add postgresql.cnpg.io/v1 to scheme: %v", err))
123-
}
124-
12591
if err := kustomize.ApplyKustomization(ctx, cl, barmanCloudKustomization); err != nil {
12692
Fail(fmt.Sprintf("failed to apply kustomization: %v", err))
12793
}

test/e2e/internal/client/client.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@ package client
1919
import (
2020
"fmt"
2121

22+
certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
23+
cloudnativepgv1 "github.com/cloudnative-pg/api/pkg/api/v1"
24+
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
25+
appsv1 "k8s.io/api/apps/v1"
26+
corev1 "k8s.io/api/core/v1"
27+
rbacv1 "k8s.io/api/rbac/v1"
28+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2229
"k8s.io/client-go/kubernetes"
2330
"k8s.io/client-go/rest"
2431
"sigs.k8s.io/controller-runtime/pkg/client"
2532
"sigs.k8s.io/controller-runtime/pkg/client/config"
33+
34+
pluginBarmanCloudV1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
2635
)
2736

2837
// NewClient creates a new controller-runtime Kubernetes client.
@@ -38,6 +47,10 @@ func NewClient() (client.Client, *rest.Config, error) {
3847
return nil, nil, fmt.Errorf("failed to create Kubernetes client: %w", err)
3948
}
4049

50+
if err := addScheme(cl); err != nil {
51+
return nil, nil, fmt.Errorf("failed to add scheme: %w", err)
52+
}
53+
4154
return cl, cfg, nil
4255
}
4356

@@ -54,3 +67,33 @@ func NewClientSet() (*kubernetes.Clientset, *rest.Config, error) {
5467

5568
return clientSet, cfg, nil
5669
}
70+
71+
func addScheme(cl client.Client) error {
72+
scheme := cl.Scheme()
73+
if err := corev1.AddToScheme(scheme); err != nil {
74+
return fmt.Errorf("failed to add core/v1 to scheme: %w", err)
75+
}
76+
if err := apiextensionsv1.AddToScheme(scheme); err != nil {
77+
return fmt.Errorf("failed to add apiextensions/v1 to scheme: %w", err)
78+
}
79+
if err := admissionregistrationv1.AddToScheme(scheme); err != nil {
80+
return fmt.Errorf("failed to add admissionregistration/v1 to scheme: %w", err)
81+
}
82+
if err := rbacv1.AddToScheme(scheme); err != nil {
83+
return fmt.Errorf("failed to add rbac/v1 to scheme: %w", err)
84+
}
85+
if err := appsv1.AddToScheme(scheme); err != nil {
86+
return fmt.Errorf("failed to add apps/v1 to scheme: %w", err)
87+
}
88+
if err := certmanagerv1.AddToScheme(scheme); err != nil {
89+
return fmt.Errorf("failed to add cert-manager/v1 to scheme: %w", err)
90+
}
91+
if err := pluginBarmanCloudV1.AddToScheme(scheme); err != nil {
92+
return fmt.Errorf("failed to add plugin-barman-cloud/v1 to scheme: %w", err)
93+
}
94+
if err := cloudnativepgv1.AddToScheme(scheme); err != nil {
95+
return fmt.Errorf("failed to add cloudnativepg/v1 to scheme: %w", err)
96+
}
97+
98+
return nil
99+
}

test/e2e/internal/tests/backup/backup_restore.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"sigs.k8s.io/controller-runtime/pkg/client"
2727

2828
internalClient "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/client"
29-
cluster2 "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/cluster"
29+
internalCluster "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/cluster"
3030
"github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/command"
3131
nmsp "github.com/cloudnative-pg/plugin-barman-cloud/test/e2e/internal/namespace"
3232

@@ -74,8 +74,8 @@ var _ = Describe("Backup and restore", func() {
7474
Namespace: src.Namespace,
7575
},
7676
src)).To(Succeed())
77-
g.Expect(cluster2.IsReady(*src)).To(BeTrue())
78-
}).WithTimeout(15 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
77+
g.Expect(internalCluster.IsReady(*src)).To(BeTrue())
78+
}).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())
7979

8080
By("Adding data to PostgreSQL")
8181
clientSet, cfg, err := internalClient.NewClientSet()
@@ -143,8 +143,8 @@ var _ = Describe("Backup and restore", func() {
143143
g.Expect(cl.Get(ctx,
144144
types.NamespacedName{Name: dst.Name, Namespace: dst.Namespace},
145145
dst)).To(Succeed())
146-
g.Expect(cluster2.IsReady(*dst)).To(BeTrue())
147-
}).WithTimeout(15 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
146+
g.Expect(internalCluster.IsReady(*dst)).To(BeTrue())
147+
}).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())
148148

149149
By("Verifying the data exists in the restored instance")
150150
output, _, err := command.ExecuteInContainer(ctx,
@@ -169,7 +169,7 @@ var _ = Describe("Backup and restore", func() {
169169
g.Expect(cl.Get(ctx, types.NamespacedName{Name: backup.Name, Namespace: backup.Namespace},
170170
backup)).To(Succeed())
171171
g.Expect(backup.Status.Phase).To(BeEquivalentTo(v1.BackupPhaseCompleted))
172-
}).Within(2 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
172+
}).Within(3 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
173173
},
174174
Entry(
175175
"using the plugin for backup and restore on S3",

test/e2e/internal/tests/replicacluster/replica_cluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var _ = Describe("Replica cluster", func() {
8181
},
8282
src)).To(Succeed())
8383
g.Expect(cluster2.IsReady(*src)).To(BeTrue())
84-
}).WithTimeout(5 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
84+
}).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())
8585

8686
By("Adding data to PostgreSQL")
8787
clientSet, cfg, err := internalClient.NewClientSet()
@@ -107,7 +107,7 @@ var _ = Describe("Replica cluster", func() {
107107
g.Expect(cl.Get(ctx, types.NamespacedName{Name: backup.Name, Namespace: backup.Namespace},
108108
backup)).To(Succeed())
109109
g.Expect(backup.Status.Phase).To(BeEquivalentTo(cloudnativepgv1.BackupPhaseCompleted))
110-
}).Within(2 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
110+
}).Within(3 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
111111

112112
By("Creating a replica cluster")
113113
replica := testResources.ReplicaCluster
@@ -123,7 +123,7 @@ var _ = Describe("Replica cluster", func() {
123123
},
124124
replica)).To(Succeed())
125125
g.Expect(cluster2.IsReady(*replica)).To(BeTrue())
126-
}).WithTimeout(15 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
126+
}).WithTimeout(10 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())
127127

128128
By("Checking the data in the replica cluster")
129129
output, _, err := command.ExecuteInContainer(ctx,

0 commit comments

Comments
 (0)