From b74e309df9d7ca75327602f2731f7a2f5d3f5b25 Mon Sep 17 00:00:00 2001 From: Sebastien Guilloux Date: Wed, 1 Jul 2020 19:59:27 +0200 Subject: [PATCH] Wait for E2E Job Pod log stream to be over before finishing E2E tests (#3377) I think there are cases (eg. OCP) where streaming the E2E Pod logs is slower than others. In such case, we may end up in a situation where, at the end of the E2E tests, we haven't retrieved the full go test log. Which then makes the job fail in CI since test logs cannot be parsed and transformed to XML. This commit solves it by waiting for the streamStatus chan to report something (either err or nil), before returning from the `monitorTestJob` function. --- test/e2e/cmd/run/run.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/e2e/cmd/run/run.go b/test/e2e/cmd/run/run.go index c11340ecb5..9068d3f31a 100644 --- a/test/e2e/cmd/run/run.go +++ b/test/e2e/cmd/run/run.go @@ -432,7 +432,12 @@ func (h *helper) monitorTestJob(client *kubernetes.Clientset) error { } } case corev1.PodSucceeded: - log.Info("Tests completed successfully", "name", newPod.Name) + log.Info("Test Job succeeded, waiting for log stream to be over", "name", newPod.Name) + streamErr := <-streamStatus + if streamErr != nil { + log.Error(streamErr, "Stream failure") + err = streamErr + } cancelFunc() case corev1.PodFailed: log.Info("Pod is in failed state", "name", newPod.Name) @@ -484,14 +489,12 @@ func (h *helper) streamTestJobOutput(streamStatus chan<- error, client *kubernet writer := io.MultiWriter(outputs...) var buffer [logBufferSize]byte - if _, err := io.CopyBuffer(writer, stream, buffer[:]); err != nil { - if err == io.EOF { - log.Info("Log stream ended") - return - } - + if _, err := io.CopyBuffer(writer, stream, buffer[:]); err != nil && err != io.EOF { streamStatus <- err + return } + log.Info("Log stream ended") + streamStatus <- nil } func (h *helper) kubectlApplyTemplate(templatePath string, templateParam interface{}) (string, error) {