Skip to content

Commit

Permalink
iptables: use log package to get timestamps in tests
Browse files Browse the repository at this point in the history
Useful in debugging buildkite flakes, e.g:

https://buildkite.com/gvisor/pipeline/builds/26145

PiperOrigin-RevId: 586125192
  • Loading branch information
kevinGC authored and gvisor-bot committed Nov 28, 2023
1 parent 9cf9d1d commit b4ef436
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions test/iptables/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ go_test(
"manual",
],
deps = [
"//pkg/log",
"//pkg/test/dockerutil",
"//pkg/test/testutil",
],
Expand Down
20 changes: 13 additions & 7 deletions test/iptables/iptables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sync"
"testing"

"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/test/dockerutil"
"gvisor.dev/gvisor/pkg/test/testutil"
)
Expand Down Expand Up @@ -50,7 +51,8 @@ func singleTest(t *testing.T, test TestCase) {

func iptablesTest(t *testing.T, test TestCase, ipv6 bool) {
if _, ok := Tests[test.Name()]; !ok {
t.Fatalf("no test found with name %q. Has it been registered?", test.Name())
log.Infof("no test found with name %q. Has it been registered?", test.Name())
t.FailNow()
}

// Wait for the local and container goroutines to finish.
Expand All @@ -63,9 +65,9 @@ func iptablesTest(t *testing.T, test TestCase, ipv6 bool) {
d := dockerutil.MakeContainer(ctx, t)
defer func() {
if logs, err := d.Logs(context.Background()); err != nil {
t.Logf("Failed to retrieve container logs.")
log.Infof("Failed to retrieve container logs.")
} else {
t.Logf("=== Container logs: ===\n%s", logs)
log.Infof("=== Container logs: ===\n%s", logs)
}
// Use a new context, as cleanup should run even when we
// timeout.
Expand All @@ -83,22 +85,26 @@ func iptablesTest(t *testing.T, test TestCase, ipv6 bool) {
args = append(args, "-ipv6")
}
if err := d.Spawn(ctx, opts, args...); err != nil {
t.Fatalf("docker run failed: %v", err)
log.Infof("docker run failed: %v", err)
t.FailNow()
}

// Get the container IP.
ip, err := d.FindIP(ctx, ipv6)
if err != nil {
// If ipv6 is not configured, don't fail.
if ipv6 && err == dockerutil.ErrNoIP {
t.Skipf("No ipv6 address is available.")
log.Infof("No ipv6 address is available.")
t.Skip()
}
t.Fatalf("failed to get container IP: %v", err)
log.Infof("failed to get container IP: %v", err)
t.FailNow()
}

// Give the container our IP.
if err := sendIP(ip); err != nil {
t.Fatalf("failed to send IP to container: %v", err)
log.Infof("failed to send IP to container: %v", err)
t.FailNow()
}

// Run our side of the test.
Expand Down

0 comments on commit b4ef436

Please sign in to comment.