From 75e864fc7529bf71484ecabbb2ce2264e96399cf Mon Sep 17 00:00:00 2001 From: Eyal Soha Date: Thu, 16 Apr 2020 15:14:44 -0700 Subject: Use multierr in packetimpact Connection.Close() PiperOrigin-RevId: 306930652 --- WORKSPACE | 14 ++++++++++++++ test/packetimpact/testbench/BUILD | 1 + test/packetimpact/testbench/connections.go | 13 ++++++------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index bca63c0d9..c40e03ad2 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -400,6 +400,20 @@ go_repository( version = "v0.20.0", ) +go_repository( + name = "org_uber_go_atomic", + importpath = "go.uber.org/atomic", + version = "v1.6.0", + sum = "h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=", +) + +go_repository( + name = "org_uber_go_multierr", + importpath = "go.uber.org/multierr", + version = "v1.5.0", + sum = "h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=", +) + # BigQuery Dependencies for Benchmarks go_repository( name = "com_google_cloud_go", diff --git a/test/packetimpact/testbench/BUILD b/test/packetimpact/testbench/BUILD index 838a10ffe..b6a254882 100644 --- a/test/packetimpact/testbench/BUILD +++ b/test/packetimpact/testbench/BUILD @@ -28,6 +28,7 @@ go_library( "@org_golang_google_grpc//:go_default_library", "@org_golang_google_grpc//keepalive:go_default_library", "@org_golang_x_sys//unix:go_default_library", + "@org_uber_go_multierr//:go_default_library", ], ) diff --git a/test/packetimpact/testbench/connections.go b/test/packetimpact/testbench/connections.go index c1b3c4380..f84fd8ba7 100644 --- a/test/packetimpact/testbench/connections.go +++ b/test/packetimpact/testbench/connections.go @@ -26,6 +26,7 @@ import ( "time" "github.com/mohae/deepcopy" + "go.uber.org/multierr" "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/header" @@ -382,17 +383,15 @@ func (conn *Connection) match(override, received Layers) bool { // Close frees associated resources held by the Connection. func (conn *Connection) Close() { - if err := conn.sniffer.close(); err != nil { - conn.t.Fatal(err) - } - if err := conn.injector.close(); err != nil { - conn.t.Fatal(err) - } + errs := multierr.Combine(conn.sniffer.close(), conn.injector.close()) for _, s := range conn.layerStates { if err := s.close(); err != nil { - conn.t.Fatalf("unable to close %+v: %s", s, err) + errs = multierr.Append(errs, fmt.Errorf("unable to close %+v: %s", s, err)) } } + if errs != nil { + conn.t.Fatalf("unable to close %+v: %s", conn, errs) + } } // CreateFrame builds a frame for the connection with layer overriding defaults -- cgit v1.2.3