@@ -182,15 +182,17 @@ torchvision==0.12.0
182182 test .Eventually (AppWrapper (test , namespace , aw .Name ), TestTimeoutMedium ).
183183 Should (WithTransform (AppWrapperState , Equal (mcadv1beta1 .AppWrapperStateActive )))
184184
185+ defer troubleshooting (test , job )
186+
185187 test .T ().Logf ("Waiting for Job %s/%s to complete successfully" , job .Namespace , job .Name )
186- test .Eventually (Job (test , namespace , job .Name ), TestTimeoutLong ).
188+ test .Eventually (Job (test , job . Namespace , job .Name ), TestTimeoutLong ).
187189 Should (WithTransform (ConditionStatus (batchv1 .JobComplete ), Equal (corev1 .ConditionTrue )))
188190
189191 // Refresh the job to get the generated pod selector
190- job = GetJob (test , namespace , job .Name )
192+ job = GetJob (test , job . Namespace , job .Name )
191193
192194 // Get the job Pod
193- pods := GetPods (test , namespace , metav1.ListOptions {
195+ pods := GetPods (test , job . Namespace , metav1.ListOptions {
194196 LabelSelector : labels .FormatLabels (job .Spec .Selector .MatchLabels )},
195197 )
196198 test .Expect (pods ).To (HaveLen (1 ))
@@ -199,3 +201,25 @@ torchvision==0.12.0
199201 test .T ().Logf ("Printing Job %s/%s logs" , job .Namespace , job .Name )
200202 test .T ().Log (GetPodLogs (test , & pods [0 ], corev1.PodLogOptions {}))
201203}
204+
205+ func troubleshooting (test Test , job * batchv1.Job ) {
206+ if ! test .T ().Failed () {
207+ return
208+ }
209+ job = GetJob (test , job .Namespace , job .Name )
210+
211+ test .T ().Errorf ("Job %s/%s hasn't completed in time: %s" , job .Namespace , job .Name , job )
212+
213+ pods := GetPods (test , job .Namespace , metav1.ListOptions {
214+ LabelSelector : labels .FormatLabels (job .Spec .Selector .MatchLabels )},
215+ )
216+
217+ if len (pods ) == 0 {
218+ test .T ().Errorf ("Job %s/%s has no pods scheduled" , job .Namespace , job .Name )
219+ } else {
220+ for i , pod := range pods {
221+ test .T ().Logf ("Printing Pod %s/%s logs" , pod .Namespace , pod .Name )
222+ test .T ().Log (GetPodLogs (test , & pods [i ], corev1.PodLogOptions {}))
223+ }
224+ }
225+ }
0 commit comments