From 616401e3e6d0e28f71a15264300af28e96643270 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Mon, 3 May 2021 17:39:46 -0700 Subject: [PATCH 1/6] batch logs output to speedup command --- pkg/minikube/logs/logs.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/minikube/logs/logs.go b/pkg/minikube/logs/logs.go index ded55ea265d4..a6d966c19cd0 100644 --- a/pkg/minikube/logs/logs.go +++ b/pkg/minikube/logs/logs.go @@ -184,10 +184,12 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.Cluster failed = append(failed, name) continue } + l := "" scanner := bufio.NewScanner(&b) for scanner.Scan() { - out.Styled(style.Empty, scanner.Text()) + l += scanner.Text() + "\n" } + out.Styled(style.Empty, l) } if len(failed) > 0 { @@ -223,10 +225,12 @@ func outputLastStart() error { return fmt.Errorf("failed to open file %s: %v", fp, err) } defer f.Close() + l := "" s := bufio.NewScanner(f) for s.Scan() { - out.Styled(style.Empty, s.Text()) + l += s.Text() + "\n" } + out.Styled(style.Empty, l) if err := s.Err(); err != nil { return fmt.Errorf("failed to read file %s: %v", fp, err) } From e2690573b01f957ecb72c3403c66185cdfd96157 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Mon, 3 May 2021 18:02:59 -0700 Subject: [PATCH 2/6] added minikube logs timeout integration test --- test/integration/aaa_download_only_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/integration/aaa_download_only_test.go b/test/integration/aaa_download_only_test.go index f14328126f2b..b3c4ece40e51 100644 --- a/test/integration/aaa_download_only_test.go +++ b/test/integration/aaa_download_only_test.go @@ -158,6 +158,14 @@ func TestDownloadOnly(t *testing.T) { } }) + t.Run("minikube logs", func(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), Seconds(5)) + args := append([]string{"logs", "-p", profile}) + if _, err := Run(t, exec.CommandContext(ctx, Target(), args...)); err != nil { + t.Errorf("minikube logs failed with error: %v", err) + } + }) + }) } From 8071aad4df2e29b75f29638a4cb4dc17a086c556 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 4 May 2021 09:40:01 -0700 Subject: [PATCH 3/6] add explicit timeout failure message --- test/integration/aaa_download_only_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/integration/aaa_download_only_test.go b/test/integration/aaa_download_only_test.go index b3c4ece40e51..bce46be53cff 100644 --- a/test/integration/aaa_download_only_test.go +++ b/test/integration/aaa_download_only_test.go @@ -160,10 +160,14 @@ func TestDownloadOnly(t *testing.T) { t.Run("minikube logs", func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), Seconds(5)) - args := append([]string{"logs", "-p", profile}) + defer cancel() + args := []string{"logs", "-p", profile} if _, err := Run(t, exec.CommandContext(ctx, Target(), args...)); err != nil { t.Errorf("minikube logs failed with error: %v", err) } + if err := ctx.Err(); err != nil { + t.Error("minikube logs expected to finish by 5 seconds, but took longer") + } }) }) From 29a68257146f9c8babfc8a990c48f1936567e1db Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 4 May 2021 13:41:40 -0700 Subject: [PATCH 4/6] explicitly check for DeadlineExceeded --- test/integration/aaa_download_only_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/aaa_download_only_test.go b/test/integration/aaa_download_only_test.go index bce46be53cff..cf4abd638187 100644 --- a/test/integration/aaa_download_only_test.go +++ b/test/integration/aaa_download_only_test.go @@ -165,7 +165,7 @@ func TestDownloadOnly(t *testing.T) { if _, err := Run(t, exec.CommandContext(ctx, Target(), args...)); err != nil { t.Errorf("minikube logs failed with error: %v", err) } - if err := ctx.Err(); err != nil { + if err := ctx.Err(); err == context.DeadlineExceeded { t.Error("minikube logs expected to finish by 5 seconds, but took longer") } }) From 459c42bf4847a22defb82dad17efd59e0f87aed5 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 4 May 2021 16:12:19 -0700 Subject: [PATCH 5/6] dont check exit code of minikube logs in logs duration test --- test/integration/aaa_download_only_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/integration/aaa_download_only_test.go b/test/integration/aaa_download_only_test.go index cf4abd638187..13c37e837331 100644 --- a/test/integration/aaa_download_only_test.go +++ b/test/integration/aaa_download_only_test.go @@ -158,13 +158,12 @@ func TestDownloadOnly(t *testing.T) { } }) - t.Run("minikube logs", func(t *testing.T) { + // checks if the duration of `minikube logs` takes longer than 5 seconds + t.Run("LogsDuration", func(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), Seconds(5)) defer cancel() args := []string{"logs", "-p", profile} - if _, err := Run(t, exec.CommandContext(ctx, Target(), args...)); err != nil { - t.Errorf("minikube logs failed with error: %v", err) - } + Run(t, exec.CommandContext(ctx, Target(), args...)) if err := ctx.Err(); err == context.DeadlineExceeded { t.Error("minikube logs expected to finish by 5 seconds, but took longer") } From 9d98c09f036dd84ae129acf6d658fcfdfb57a11d Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 4 May 2021 16:30:29 -0700 Subject: [PATCH 6/6] added back error check --- test/integration/aaa_download_only_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/integration/aaa_download_only_test.go b/test/integration/aaa_download_only_test.go index 13c37e837331..b48bcdb275a1 100644 --- a/test/integration/aaa_download_only_test.go +++ b/test/integration/aaa_download_only_test.go @@ -163,7 +163,9 @@ func TestDownloadOnly(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), Seconds(5)) defer cancel() args := []string{"logs", "-p", profile} - Run(t, exec.CommandContext(ctx, Target(), args...)) + if _, err := Run(t, exec.CommandContext(ctx, Target(), args...)); err != nil { + t.Logf("minikube logs failed with error: %v", err) + } if err := ctx.Err(); err == context.DeadlineExceeded { t.Error("minikube logs expected to finish by 5 seconds, but took longer") }