Skip to content

Commit cd1fcb4

Browse files
authored
test: more e2e test for monovertex (#2313)
Signed-off-by: Derek Wang <[email protected]>
1 parent 97b84cf commit cd1fcb4

File tree

4 files changed

+89
-2
lines changed

4 files changed

+89
-2
lines changed

test/fixtures/expect.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ func (t *Expect) DaemonPodLogContains(pipelineName, regex string, opts ...PodLog
204204
return t
205205
}
206206

207+
func (t *Expect) MvtxDaemonPodsRunning() *Expect {
208+
t.t.Helper()
209+
timeout := 2 * time.Minute
210+
if err := WaitForMvtxDaemonPodsRunning(t.kubeClient, Namespace, t.monoVertex.Name, timeout); err != nil {
211+
t.t.Fatalf("Expected mvtx daemon pods of %q running: %v", t.monoVertex.Name, err)
212+
}
213+
return t
214+
}
215+
207216
func (t *Expect) When() *When {
208217
return &When{
209218
t: t.t,

test/fixtures/util.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func WaitForMonoVertexPodRunning(kubeClient kubernetes.Interface, monoVertexClie
280280
}
281281
ok := len(podList.Items) > 0 && len(podList.Items) == monoVertex.CalculateReplicas() // pod number should equal to desired replicas
282282
for _, p := range podList.Items {
283-
ok = ok && p.Status.Phase == corev1.PodRunning
283+
ok = ok && isPodReady(p)
284284
}
285285
if ok {
286286
return nil
@@ -378,6 +378,26 @@ func WaitForDaemonPodsRunning(kubeClient kubernetes.Interface, namespace, pipeli
378378
}
379379
}
380380

381+
func WaitForMvtxDaemonPodsRunning(kubeClient kubernetes.Interface, namespace, mvtx string, timeout time.Duration) error {
382+
ctx, cancel := context.WithTimeout(context.Background(), timeout)
383+
defer cancel()
384+
labelSelector := fmt.Sprintf("%s=%s,%s=%s", dfv1.KeyMonoVertexName, mvtx, dfv1.KeyComponent, dfv1.ComponentMonoVertexDaemon)
385+
for {
386+
podList, err := kubeClient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelector, FieldSelector: "status.phase=Running"})
387+
if err != nil {
388+
return fmt.Errorf("error getting mvtx daemon pod name: %w", err)
389+
}
390+
ok := len(podList.Items) > 0
391+
for _, p := range podList.Items {
392+
ok = ok && p.Status.Phase == corev1.PodRunning
393+
}
394+
if ok {
395+
return nil
396+
}
397+
time.Sleep(2 * time.Second)
398+
}
399+
}
400+
381401
func VertexPodLogNotContains(ctx context.Context, kubeClient kubernetes.Interface, namespace, pipelineName, vertexName, regex string, opts ...PodLogCheckOption) (bool, error) {
382402
labelSelector := fmt.Sprintf("%s=%s,%s=%s", dfv1.KeyPipelineName, pipelineName, dfv1.KeyVertexName, vertexName)
383403
podList, err := kubeClient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelector, FieldSelector: "status.phase=Running"})

test/fixtures/when.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,50 @@ func (w *When) DaemonPodPortForward(pipelineName string, localPort, remotePort i
243243
return w
244244
}
245245

246+
func (w *When) MonoVertexPodPortForward(localPort, remotePort int) *When {
247+
w.t.Helper()
248+
labelSelector := fmt.Sprintf("%s=%s,%s=%s", dfv1.KeyComponent, dfv1.ComponentMonoVertex, dfv1.KeyMonoVertexName, w.monoVertex.Name)
249+
ctx := context.Background()
250+
podList, err := w.kubeClient.CoreV1().Pods(Namespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelector, FieldSelector: "status.phase=Running"})
251+
if err != nil {
252+
w.t.Fatalf("Error getting mvtx pod name: %v", err)
253+
}
254+
podName := podList.Items[0].GetName()
255+
w.t.Logf("MonoVertex POD name: %s", podName)
256+
257+
stopCh := make(chan struct{}, 1)
258+
if err = PodPortForward(w.restConfig, Namespace, podName, localPort, remotePort, stopCh); err != nil {
259+
w.t.Fatalf("Expected mvtx pod port-forward: %v", err)
260+
}
261+
if w.portForwarderStopChannels == nil {
262+
w.portForwarderStopChannels = make(map[string]chan struct{})
263+
}
264+
w.portForwarderStopChannels[podName] = stopCh
265+
return w
266+
}
267+
268+
func (w *When) MvtxDaemonPodPortForward(localPort, remotePort int) *When {
269+
w.t.Helper()
270+
labelSelector := fmt.Sprintf("%s=%s,%s=%s", dfv1.KeyComponent, dfv1.ComponentMonoVertexDaemon, dfv1.KeyMonoVertexName, w.monoVertex.Name)
271+
ctx := context.Background()
272+
podList, err := w.kubeClient.CoreV1().Pods(Namespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelector, FieldSelector: "status.phase=Running"})
273+
if err != nil {
274+
w.t.Fatalf("Error getting mvtx daemon pod name: %v", err)
275+
}
276+
podName := podList.Items[0].GetName()
277+
w.t.Logf("MonoVertex Daemon POD name: %s", podName)
278+
279+
stopCh := make(chan struct{}, 1)
280+
if err = PodPortForward(w.restConfig, Namespace, podName, localPort, remotePort, stopCh); err != nil {
281+
w.t.Fatalf("Expected mvtx daemon pod port-forward: %v", err)
282+
}
283+
if w.portForwarderStopChannels == nil {
284+
w.portForwarderStopChannels = make(map[string]chan struct{})
285+
}
286+
w.portForwarderStopChannels[podName] = stopCh
287+
return w
288+
}
289+
246290
func (w *When) UXServerPodPortForward(localPort, remotePort int) *When {
247291
w.t.Helper()
248292
labelSelector := fmt.Sprintf("%s=%s", dfv1.KeyComponent, dfv1.ComponentUXServer)

test/monovertex-e2e/monovertex_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/stretchr/testify/suite"
2525

26+
dfv1 "github.com/numaproj/numaflow/pkg/apis/numaflow/v1alpha1"
2627
. "github.com/numaproj/numaflow/test/fixtures"
2728
)
2829

@@ -35,7 +36,20 @@ func (s *MonoVertexSuite) TestMonoVertexWithTransformer() {
3536
When().CreateMonoVertexAndWait()
3637
defer w.DeleteMonoVertexAndWait()
3738

38-
w.Expect().MonoVertexPodsRunning()
39+
w.Expect().MonoVertexPodsRunning().MvtxDaemonPodsRunning()
40+
41+
defer w.MonoVertexPodPortForward(8931, dfv1.MonoVertexMetricsPort).
42+
MvtxDaemonPodPortForward(3232, dfv1.MonoVertexDaemonServicePort).
43+
TerminateAllPodPortForwards()
44+
45+
// Check metrics endpoints
46+
HTTPExpect(s.T(), "https://localhost:8931").GET("/metrics").
47+
Expect().
48+
Status(200)
49+
50+
HTTPExpect(s.T(), "https://localhost:3232").GET("/metrics").
51+
Expect().
52+
Status(200)
3953

4054
// Expect the messages to be processed by the transformer.
4155
w.Expect().MonoVertexPodLogContains("AssignEventTime", PodLogCheckOptionWithContainer("transformer"))

0 commit comments

Comments
 (0)