From d21fd7b8cf725f7bdf4d775e7488d5bdd81f6ef2 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 10 Jul 2020 13:00:41 +0200 Subject: [PATCH] Do not fail (divide by zero) if terminal width is not set. Improved a bit the ACI e2e test, happy that it catches this error (this was going to break the log gRPC API) --- azure/aci.go | 3 +++ tests/aci-e2e/e2e-aci_test.go | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/azure/aci.go b/azure/aci.go index 04e39e7d..d94a61d0 100644 --- a/azure/aci.go +++ b/azure/aci.go @@ -280,6 +280,9 @@ func streamLogs(ctx context.Context, aciContext store.AciContext, containerGroup } func getBacktrackLines(lines []string, terminalWidth int) int { + if terminalWidth == 0 { // no terminal width has been set, do not divide by zero + return len(lines) + } numLines := 0 for i := 0; i < len(lines)-1; i++ { numLines++ diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index f9a85ac8..716f0eab 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -117,13 +117,18 @@ func (s *E2eACISuite) TestACIRunSingleContainer() { outChan := make(chan string) go func() { - output, _ := ctx.Exec() + output, err := ctx.Exec() + // check the process is cancelled by the test, not another unexpected error + Expect(err.Error()).To(ContainSubstring("timed out")) outChan <- output }() + // Ensure logs -- follow is strated before we curl nginx + time.Sleep(5 * time.Second) s.NewCommand("curl", nginxExposedURL+"/test").ExecOrDie() // Give the `logs --follow` a little time to get logs of the curl call - time.Sleep(10 * time.Second) + time.Sleep(5 * time.Second) + // Trigger a timeout to make ctx.Exec exit timeChan <- time.Now()