Skip to content

Commit

Permalink
test(experiments): e2e test for service port mappings
Browse files Browse the repository at this point in the history
Signed-off-by: Yohan Belval <[email protected]>
  • Loading branch information
yohanb committed Apr 29, 2024
1 parent 4ca3dea commit 9f31bbd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/e2e/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,29 @@ func (s *ExperimentSuite) TestExperimentWithMultiportServiceAndScaleDownDelay()
ExpectExperimentServiceCount("experiment-with-multiport-service", 0)
}

func (s *ExperimentSuite) TestExperimentWithServicePortMappingsAndScaleDownDelay() {
g := s.Given()
g.ApplyManifests("@functional/experiment-with-service-port-mappings.yaml")
g.When().
WaitForExperimentPhase("experiment-with-service-port-mappings", "Running").
WaitForExperimentCondition("experiment-with-service-port-mappings", func(ex *rov1.Experiment) bool {
return s.GetReplicaSetFromExperiment(ex, "test").Status.Replicas == 1
}, "number-of-rs-pods-meet", fixtures.E2EWaitTimeout).
Then().
ExpectExperimentTemplateReplicaSetNumReplicas("experiment-with-service-port-mappings", "test", 1).
ExpectExperimentServiceCount("experiment-with-service-port-mappings", 1).
ExpectExperimentServicePortMappings("experiment-with-service-port-mappings", "test", 0, 80, 8080).
ExpectExperimentServicePortMappings("experiment-with-service-port-mappings", "test", 1, 81, 8081).
When().
WaitForExperimentPhase("experiment-with-service-port-mappings", "Successful").
WaitForExperimentCondition("experiment-with-service-port-mappings", func(ex *rov1.Experiment) bool {
return s.GetReplicaSetFromExperiment(ex, "test").Status.Replicas == 0
}, "number-of-rs-pods-meet", fixtures.E2EWaitTimeout).
Then().
ExpectExperimentTemplateReplicaSetNumReplicas("experiment-with-service-port-mappings", "test", 0).
ExpectExperimentServiceCount("experiment-with-service-port-mappings", 0)
}

func (s *ExperimentSuite) TestExperimentWithDryRunMetrics() {
g := s.Given()
g.ApplyManifests("@functional/experiment-dry-run-analysis.yaml")
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/functional/experiment-with-service-port-mappings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: argoproj.io/v1alpha1
kind: Experiment
metadata:
name: experiment-with-service-port-mappings
spec:
duration: 10s
scaleDownDelaySeconds: 5
# List of pod template specs to run in the experiment as ReplicaSets
templates:
- name: test
replicas: 1
service:
name: test-service-with-port-mappings
portMappings:
- port: 80
containerPort: 8080
- port: 81
containerPort: 8081
selector:
matchLabels:
app: xperiment-with-service-port-mappings
template:
metadata:
labels:
app: xperiment-with-service-port-mappings
spec:
containers:
- name: xperiment-with-service-port-mappings
image: nginx:1.19-alpine
resources:
requests:
memory: 16Mi
cpu: 1m
ports:
- name: testport1
protocol: TCP
containerPort: 8080
- name: testport2
protocol: TCP
containerPort: 8081
7 changes: 7 additions & 0 deletions test/fixtures/then.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ func (t *Then) ExpectExperimentServiceCount(experimentName string, expectedCount
})
}

func (t *Then) ExpectExperimentServicePortMappings(experimentName string, templateName string, portIdx int, expectedPort int, expectedTargetPort int) *Then {
return t.ExpectExperimentServices(fmt.Sprintf("experiment service port and idx %d, port %d mapped to target port: %d", portIdx, expectedPort, expectedTargetPort), experimentName, func(templateToService map[string]*corev1.Service) bool {
return templateToService[templateName].Spec.Ports[portIdx].Port == int32(expectedPort) &&
templateToService[templateName].Spec.Ports[portIdx].TargetPort.IntVal == int32(expectedTargetPort)
})
}

func (t *Then) ExpectExperiments(expectation string, expectFunc ExperimentListExpectation) *Then {
exps := t.GetRolloutExperiments()
if !expectFunc(&exps) {
Expand Down

0 comments on commit 9f31bbd

Please sign in to comment.