From 5c4a7872dcf5bf1c6850fc95fd335769787e0ade Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Tue, 1 Oct 2024 14:46:02 +1000 Subject: [PATCH] tmp for testing --- .../scaling/kube_scaling_integration_test.go | 2 +- internal/integration/harness.go | 60 ++++++++++--------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/backend/controller/scaling/kube_scaling_integration_test.go b/backend/controller/scaling/kube_scaling_integration_test.go index f11c3bcb13..4bb48942d0 100644 --- a/backend/controller/scaling/kube_scaling_integration_test.go +++ b/backend/controller/scaling/kube_scaling_integration_test.go @@ -58,7 +58,7 @@ func TestKubeScaling(t *testing.T) { defer routineStopped.Done() for !done.Load() { in.Call("echo", "echo", "Bob", func(t testing.TB, response string) { - if !strings.Contains(response, "Bob") { + if !strings.Contains(response, "Bob2") { failure.Store(fmt.Errorf("unexpected response: %s", response)) return } diff --git a/internal/integration/harness.go b/internal/integration/harness.go index 67dd50c1b0..e71de185af 100644 --- a/internal/integration/harness.go +++ b/internal/integration/harness.go @@ -387,34 +387,7 @@ func (i TestContext) AssertWithRetry(t testing.TB, assertion Action) { } select { case <-waitCtx.Done(): - if client, ok := i.kubeClient.Get(); ok { - Infof("Kube logs:") - list, err := client.CoreV1().Pods(i.kubeNamespace).List(i, kubemeta.ListOptions{}) - if err == nil { - for _, pod := range list.Items { - Infof("\n\n\n========== Pod %s ==========", pod.Name) - for _, container := range pod.Spec.Containers { - Infof("\n\n\n----------- Pod %s Container %s --------", pod.Name, container.Name) - req := client.CoreV1().Pods(i.kubeNamespace).GetLogs(pod.Name, &kubecore.PodLogOptions{Container: container.Name}) - podLogs, err := req.Stream(context.Background()) - if err != nil { - Infof("Error getting logs for pod %s: %v", pod.Name, err) - continue - } - buf := new(bytes.Buffer) - _, err = io.Copy(buf, podLogs) - if err != nil { - Infof("Error copying logs for pod %s: %v", pod.Name, err) - continue - } - str := buf.String() - Infof("%s", str) - _ = podLogs.Close() - } - } - } - - } + i.maybeDumpKubePods(t, "assertion-timeout") t.Fatalf("Timed out waiting for assertion to pass: %s", err) case <-time.After(time.Millisecond * 200): @@ -422,6 +395,37 @@ func (i TestContext) AssertWithRetry(t testing.TB, assertion Action) { } } +func (i TestContext) maybeDumpKubePods(t testing.TB, from string) { + if client, ok := i.kubeClient.Get(); ok { + t.Logf("Kube logs from %s:", from) + list, err := client.CoreV1().Pods(i.kubeNamespace).List(i, kubemeta.ListOptions{}) + if err == nil { + for _, pod := range list.Items { + t.Logf("\n\n\n========== Pod %s ==========", pod.Name) + for _, container := range pod.Spec.Containers { + t.Logf("\n\n\n----------- Pod %s Container %s --------", pod.Name, container.Name) + req := client.CoreV1().Pods(i.kubeNamespace).GetLogs(pod.Name, &kubecore.PodLogOptions{Container: container.Name}) + podLogs, err := req.Stream(context.Background()) + if err != nil { + t.Logf("Error getting logs for pod %s: %v", pod.Name, err) + continue + } + buf := new(bytes.Buffer) + _, err = io.Copy(buf, podLogs) + if err != nil { + t.Logf("Error copying logs for pod %s: %v", pod.Name, err) + continue + } + str := buf.String() + t.Logf("%s", str) + _ = podLogs.Close() + } + } + } + + } +} + // Run an assertion, wrapping testing.TB in an implementation that panics on failure, propagating the error. func (i TestContext) runAssertionOnce(t testing.TB, assertion Action) (err error) { t.Helper()