Skip to content

Commit 7dcdb26

Browse files
authored
Fix light weight job submitter e2e flaky test (#4092)
Signed-off-by: You-Cheng Lin (Owen) <[email protected]>
1 parent c9fa013 commit 7dcdb26

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

ray-operator/test/e2erayjobsubmitter/rayjob_submitter_test.go

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,7 @@ func TestRayJobSubmitter(t *testing.T) {
141141
submitterPod := Pods(test, namespace.Name, LabelSelector("job-name=delete-submitter-pod-after-submission"))(g)[0]
142142

143143
// Wait for the submitter pod to have log indicating successful submission
144-
g.Eventually(func() bool {
145-
logs, err := test.Client().Core().CoreV1().Pods(namespace.Name).GetLogs(submitterPod.Name, &corev1.PodLogOptions{Container: "ray-job-submitter"}).Stream(test.Ctx())
146-
if err != nil {
147-
return false
148-
}
149-
defer logs.Close()
150-
logsBytes, err := io.ReadAll(logs)
151-
if err != nil {
152-
return false
153-
}
154-
logsString := string(logsBytes)
155-
return strings.Contains(logsString, "SUCC -- Job '")
156-
}, TestTimeoutMedium).Should(BeTrue())
144+
g.Eventually(checkSubmitterPodLogs(test, namespace.Name, submitterPod.Name, []string{"SUCC -- Job '"}), TestTimeoutMedium).Should(BeTrue())
157145

158146
// Delete the submitter pod after successful submission
159147
err = test.Client().Core().CoreV1().Pods(namespace.Name).Delete(test.Ctx(), submitterPod.Name, metav1.DeleteOptions{})
@@ -169,19 +157,8 @@ func TestRayJobSubmitter(t *testing.T) {
169157
newSubmitterPod := Pods(test, namespace.Name, LabelSelector("job-name=delete-submitter-pod-after-submission"))(g)[0]
170158

171159
// Check the logs of the new submitter pod
172-
logs, err := test.Client().Core().CoreV1().Pods(namespace.Name).GetLogs(newSubmitterPod.Name, &corev1.PodLogOptions{Container: "ray-job-submitter"}).Stream(test.Ctx())
173-
g.Expect(err).NotTo(HaveOccurred())
174-
defer logs.Close()
175-
logsBytes, err := io.ReadAll(logs)
176-
g.Expect(err).NotTo(HaveOccurred())
177-
logContent := string(logsBytes)
178-
// Verify the logs contain expected content
179-
g.Expect(logContent).To(ContainSubstring("has already been submitted, tailing logs."))
180-
g.Expect(logContent).To(ContainSubstring("test_counter got 1"))
181-
g.Expect(logContent).To(ContainSubstring("test_counter got 2"))
182-
g.Expect(logContent).To(ContainSubstring("test_counter got 3"))
183-
g.Expect(logContent).To(ContainSubstring("test_counter got 4"))
184-
g.Expect(logContent).To(ContainSubstring("test_counter got 5"))
160+
g.Eventually(checkSubmitterPodLogs(test, namespace.Name, newSubmitterPod.Name, []string{"has already been submitted, tailing logs.", "test_counter got 1", "test_counter got 2", "test_counter got 3", "test_counter got 4", "test_counter got 5"}), TestTimeoutMedium).Should(BeTrue())
161+
185162
LogWithTimestamp(test.T(), "New submitter pod %s/%s has logs indicating successful job completion", newSubmitterPod.Namespace, newSubmitterPod.Name)
186163

187164
// Delete the RayJob
@@ -190,3 +167,28 @@ func TestRayJobSubmitter(t *testing.T) {
190167
LogWithTimestamp(test.T(), "Deleted RayJob %s/%s successfully", rayJob.Namespace, rayJob.Name)
191168
})
192169
}
170+
171+
func checkSubmitterPodLogs(test Test, namespace, podName string, expectedMessages []string) func() bool {
172+
return func() bool {
173+
logs, err := test.Client().Core().CoreV1().Pods(namespace).GetLogs(podName, &corev1.PodLogOptions{Container: "ray-job-submitter"}).Stream(test.Ctx())
174+
if err != nil {
175+
return false
176+
}
177+
defer logs.Close()
178+
179+
logsBytes, err := io.ReadAll(logs)
180+
if err != nil {
181+
return false
182+
}
183+
184+
logsString := string(logsBytes)
185+
186+
// Check if all expected messages are present
187+
for _, message := range expectedMessages {
188+
if !strings.Contains(logsString, message) {
189+
return false
190+
}
191+
}
192+
return true
193+
}
194+
}

0 commit comments

Comments
 (0)