Skip to content

Commit

Permalink
tmp for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Oct 2, 2024
1 parent 4bf823d commit 5c4a787
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
60 changes: 32 additions & 28 deletions internal/integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,41 +387,45 @@ 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):
}
}
}

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()
Expand Down

0 comments on commit 5c4a787

Please sign in to comment.