diff --git a/go/lib/snet/BUILD.bazel b/go/lib/snet/BUILD.bazel index 6ba471ca9b..de6fafddc3 100644 --- a/go/lib/snet/BUILD.bazel +++ b/go/lib/snet/BUILD.bazel @@ -62,7 +62,6 @@ go_test( "//go/lib/spath/spathmeta:go_default_library", "//go/lib/xtest:go_default_library", "@com_github_golang_mock//gomock:go_default_library", - "@com_github_smartystreets_goconvey//convey:go_default_library", "@com_github_stretchr_testify//assert:go_default_library", ], ) diff --git a/go/lib/snet/addr_test.go b/go/lib/snet/addr_test.go index d3c3cc93c8..c0750dcfc1 100644 --- a/go/lib/snet/addr_test.go +++ b/go/lib/snet/addr_test.go @@ -19,7 +19,7 @@ import ( "net" "testing" - . "github.com/smartystreets/goconvey/convey" + "github.com/stretchr/testify/assert" "github.com/scionproto/scion/go/lib/addr" ) @@ -41,11 +41,11 @@ func Test_Addr_String(t *testing.T) { {address: &Addr{IA: ia, Host: host4}, result: "1-ff00:0:320,[1.2.3.4]:10000"}, {address: &Addr{IA: ia, Host: host6}, result: "1-ff00:0:320,[2001::1]:20000"}, } - Convey("Method String", t, func() { + t.Run("Method String", func(t *testing.T) { for _, test := range tests { - Convey(fmt.Sprintf("given address object %v", test.address), func() { + t.Run(fmt.Sprintf("given address object %v", test.address), func(t *testing.T) { s := test.address.String() - SoMsg("String should match", s, ShouldResemble, test.result) + assert.Equal(t, s, test.result, "String should match") }) } }) @@ -105,19 +105,18 @@ func Test_AddrFromString(t *testing.T) { host: "CS M (0x8002)", }, } - Convey("Function AddrFromString", t, func() { + t.Run("Function AddrFromString", func(t *testing.T) { for _, test := range tests { - Convey(fmt.Sprintf("given address %q", test.address), func() { - a, err := AddrFromString(test.address) - if test.isError { - SoMsg("error", err, ShouldNotBeNil) - } else { - SoMsg("error", err, ShouldBeNil) - SoMsg("ia", a.IA.String(), ShouldResemble, test.ia) - SoMsg("host", a.Host.L3.String(), ShouldResemble, test.host) - SoMsg("port", a.Host.L4, ShouldResemble, test.l4) - } - }) + t.Log(fmt.Sprintf("given address %q", test.address)) + a, err := AddrFromString(test.address) + if test.isError { + assert.Error(t, err) + } else { + assert.NoError(t, err) + assert.Equal(t, a.IA.String(), test.ia) + assert.Equal(t, a.Host.L3.String(), test.host) + assert.Equal(t, a.Host.L4, test.l4) + } } }) } diff --git a/go/lib/snet/internal/ctxmonitor/BUILD.bazel b/go/lib/snet/internal/ctxmonitor/BUILD.bazel index 3df967117c..96b1fa4eed 100644 --- a/go/lib/snet/internal/ctxmonitor/BUILD.bazel +++ b/go/lib/snet/internal/ctxmonitor/BUILD.bazel @@ -14,6 +14,6 @@ go_test( embed = [":go_default_library"], deps = [ "//go/lib/xtest:go_default_library", - "@com_github_smartystreets_goconvey//convey:go_default_library", + "@com_github_stretchr_testify//assert:go_default_library", ], ) diff --git a/go/lib/snet/internal/ctxmonitor/ctxmonitor_test.go b/go/lib/snet/internal/ctxmonitor/ctxmonitor_test.go index 12a1577723..17be8d7f9a 100644 --- a/go/lib/snet/internal/ctxmonitor/ctxmonitor_test.go +++ b/go/lib/snet/internal/ctxmonitor/ctxmonitor_test.go @@ -20,7 +20,7 @@ import ( "testing" "time" - . "github.com/smartystreets/goconvey/convey" + "github.com/stretchr/testify/assert" "github.com/scionproto/scion/go/lib/xtest" ) @@ -31,80 +31,97 @@ const ( ) func TestMonitor(t *testing.T) { - Convey("Given a monitor", t, func() { + t.Log("Given a monitor") + //m := NewMonitor() + t.Run("Add one context via Deadline, count is 1", func(t *testing.T) { m := NewMonitor() - Convey("Add one context via Deadline, count is 1", func() { - m.WithDeadline(context.Background(), time.Now().Add(time.Millisecond)) - So(m.Count(), ShouldEqual, 1) - }) - Convey("Add one context via Timeout, count is 1", func() { - m.WithTimeout(context.Background(), time.Second) - So(m.Count(), ShouldEqual, 1) - }) - Convey("Add two contexts, count is 2", func() { - m.WithTimeout(context.Background(), time.Second) - m.WithTimeout(context.Background(), time.Second) - So(m.Count(), ShouldEqual, 2) - }) - Convey("Add one context, wait for it to expire, count is 0", func() { - ctx, cancelF := m.WithTimeout(context.Background(), time.Millisecond) - xtest.AssertReadReturnsBefore(t, ctx.Done(), maxWaitTime) - So(m.Count(), ShouldEqual, 0) - cancelF() - }) - Convey("Add one context, cancel it, count is 0", func() { - _, cancelF := m.WithTimeout(context.Background(), time.Millisecond) - cancelF() - So(m.Count(), ShouldEqual, 0) - }) - Convey("Add one context, wait for parent to expire, count is 0", func() { - parent, cancelF := context.WithTimeout(context.Background(), time.Microsecond) - m.WithTimeout(parent, time.Second) - xtest.AssertReadReturnsBefore(t, parent.Done(), maxWaitTime) - So(m.Count(), ShouldEqual, 0) - cancelF() - }) - Convey("Add one context, cancel parent, count is 0", func() { - parent, parentCancelF := context.WithTimeout(context.Background(), time.Second) - m.WithTimeout(parent, time.Second) - parentCancelF() - So(m.Count(), ShouldEqual, 0) - }) - Convey("Add one context, set deadline in the past, count is 0, ctx is Done", func() { - ctx, cancelF := m.WithTimeout(context.Background(), time.Second) - m.SetDeadline(time.Now().Add(-time.Second)) - time.Sleep(sleepForCallback) - SoMsg("count", m.Count(), ShouldEqual, 0) - SoMsg("err", ctx.Err(), ShouldEqual, context.Canceled) - cancelF() - }) - Convey("Add one context, set deadline in the future, count is 1, ctx is not Done", func() { + m.WithDeadline(context.Background(), time.Now().Add(time.Millisecond)) + assert.Equal(t, m.Count(), 1) + }) + t.Run("Add one context via Timeout, count is 1", func(t *testing.T) { + m := NewMonitor() + m.WithTimeout(context.Background(), time.Second) + assert.Equal(t, m.Count(), 1) + }) + t.Run("Add two contexts, count is 2", func(t *testing.T) { + m := NewMonitor() + m.WithTimeout(context.Background(), time.Second) + m.WithTimeout(context.Background(), time.Second) + assert.Equal(t, m.Count(), 2) + }) + t.Run("Add one context, wait for it to expire, count is 0", func(t *testing.T) { + m := NewMonitor() + ctx, cancelF := m.WithTimeout(context.Background(), time.Millisecond) + xtest.AssertReadReturnsBefore(t, ctx.Done(), maxWaitTime) + assert.Equal(t, m.Count(), 0) + cancelF() + }) + t.Run("Add one context, cancel it, count is 0", func(t *testing.T) { + m := NewMonitor() + _, cancelF := m.WithTimeout(context.Background(), time.Millisecond) + cancelF() + assert.Equal(t, m.Count(), 0) + }) + t.Run("Add one context, wait for parent to expire, count is 0", func(t *testing.T) { + m := NewMonitor() + parent, cancelF := context.WithTimeout(context.Background(), time.Microsecond) + m.WithTimeout(parent, time.Second) + xtest.AssertReadReturnsBefore(t, parent.Done(), maxWaitTime) + assert.Equal(t, m.Count(), 0) + cancelF() + }) + t.Run("Add one context, cancel parent, count is 0", func(t *testing.T) { + m := NewMonitor() + parent, parentCancelF := context.WithTimeout(context.Background(), time.Second) + m.WithTimeout(parent, time.Second) + parentCancelF() + assert.Equal(t, m.Count(), 0) + }) + t.Run("Add one context, set deadline in the past, count is 0, ctx is Done", func(t *testing.T) { + m := NewMonitor() + ctx, cancelF := m.WithTimeout(context.Background(), time.Second) + m.SetDeadline(time.Now().Add(-time.Second)) + time.Sleep(sleepForCallback) + assert.Equal(t, m.Count(), 0, "count") + assert.Equal(t, ctx.Err(), context.Canceled, "err") + cancelF() + }) + t.Run("Add one context, set deadline in the future, count is 1, ctx is not Done", + func(t *testing.T) { + m := NewMonitor() ctx, cancelF := m.WithTimeout(context.Background(), time.Second) m.SetDeadline(time.Now().Add(time.Second)) time.Sleep(sleepForCallback) - SoMsg("count", m.Count(), ShouldEqual, 1) - SoMsg("err", ctx.Err(), ShouldBeNil) - cancelF() - }) - Convey("Set deadline to now, add context, ctx is immediately Done", func() { - m.SetDeadline(time.Now()) - ctx, cancelF := m.WithTimeout(context.Background(), time.Second) - SoMsg("count", m.Count(), ShouldEqual, 0) - SoMsg("err", ctx.Err(), ShouldNotBeNil) + assert.Equal(t, m.Count(), 1, "count") + assert.NoError(t, ctx.Err()) cancelF() }) - Convey("Set deadline in future, add context with deadline after, ctx is not Done", func() { + t.Run("Set deadline to now, add context, ctx is immediately Done", func(t *testing.T) { + m := NewMonitor() + m.SetDeadline(time.Now()) + ctx, cancelF := m.WithTimeout(context.Background(), time.Second) + assert.Equal(t, m.Count(), 0, "count") + assert.Error(t, ctx.Err()) + cancelF() + }) + t.Run("Set deadline in future, add context with deadline after, ctx is not Done", + func(t *testing.T) { + m := NewMonitor() deadline := time.Now().Add(5 * time.Second) m.SetDeadline(deadline) ctx, cancelF := m.WithDeadline(context.Background(), deadline.Add(time.Second)) - SoMsg("err", ctx.Err(), ShouldBeNil) + assert.NoError(t, ctx.Err()) cancelF() }) - }) } func TestDeadlineRunner(t *testing.T) { - Convey("Given a deadline runner", t, func() { + t.Log("Given a deadline runner") + t.Run("If no deadline, function is not executed", func(t *testing.T) { + var runCount int64 + assert.Equal(t, atomic.LoadInt64(&runCount), int64(0)) + }) + t.Run("If deadline in the past, function is executed", func(t *testing.T) { var runCount int64 done := make(chan struct{}) r := NewDeadlineRunner( @@ -112,40 +129,77 @@ func TestDeadlineRunner(t *testing.T) { atomic.AddInt64(&runCount, 1) close(done) }) - Convey("If no deadline, function is not executed", func() { - So(atomic.LoadInt64(&runCount), ShouldEqual, 0) - }) - Convey("If deadline in the past, function is executed", func() { - r.SetDeadline(time.Now().Add(-time.Second)) - xtest.AssertReadReturnsBefore(t, done, time.Second) - So(atomic.LoadInt64(&runCount), ShouldEqual, 1) - }) - Convey("If deadline in the future, function is not executed", func() { - r.SetDeadline(time.Now().Add(time.Second)) - So(atomic.LoadInt64(&runCount), ShouldEqual, 0) - }) - Convey("If deadline in the future and we wait, function is executed", func() { - r.SetDeadline(time.Now().Add(10 * time.Millisecond)) - xtest.AssertReadReturnsBefore(t, done, time.Second) - So(atomic.LoadInt64(&runCount), ShouldEqual, 1) - }) - Convey("If deadline in the future, and then extended, the first doesn't trigger", func() { + + r.SetDeadline(time.Now().Add(-time.Second)) + xtest.AssertReadReturnsBefore(t, done, time.Second) + assert.Equal(t, atomic.LoadInt64(&runCount), int64(1)) + }) + t.Run("If deadline in the future, function is not executed", func(t *testing.T) { + var runCount int64 + done := make(chan struct{}) + r := NewDeadlineRunner( + func() { + atomic.AddInt64(&runCount, 1) + close(done) + }) + + r.SetDeadline(time.Now().Add(time.Second)) + assert.Equal(t, atomic.LoadInt64(&runCount), int64(0)) + }) + t.Run("If deadline in the future and we wait, function is executed", func(t *testing.T) { + var runCount int64 + done := make(chan struct{}) + r := NewDeadlineRunner( + func() { + atomic.AddInt64(&runCount, 1) + close(done) + }) + + r.SetDeadline(time.Now().Add(10 * time.Millisecond)) + xtest.AssertReadReturnsBefore(t, done, time.Second) + assert.Equal(t, atomic.LoadInt64(&runCount), int64(1)) + }) + t.Run("If deadline in the future, and then extended, the first doesn't trigger", + func(t *testing.T) { + var runCount int64 + done := make(chan struct{}) + r := NewDeadlineRunner( + func() { + atomic.AddInt64(&runCount, 1) + close(done) + }) + r.SetDeadline(time.Now().Add(10 * time.Millisecond)) r.SetDeadline(time.Now().Add(time.Second)) time.Sleep(20 * time.Millisecond) - So(atomic.LoadInt64(&runCount), ShouldEqual, 0) - }) - Convey("If deadline in the future, and is then set in past, function is executed", func() { + assert.Equal(t, atomic.LoadInt64(&runCount), int64(0)) + }) + t.Run("If deadline in the future, and is then set in past, function is executed", + func(t *testing.T) { + var runCount int64 + done := make(chan struct{}) + r := NewDeadlineRunner( + func() { + atomic.AddInt64(&runCount, 1) + close(done) + }) + r.SetDeadline(time.Now().Add(time.Second)) r.SetDeadline(time.Now().Add(-time.Second)) xtest.AssertReadReturnsBefore(t, done, time.Second) - So(atomic.LoadInt64(&runCount), ShouldEqual, 1) - }) - Convey("Setting a deadline to 0 resets it, function is not executed", func() { - r.SetDeadline(time.Now().Add(10 * time.Millisecond)) - r.SetDeadline(time.Time{}) - time.Sleep(sleepForCallback) - So(atomic.LoadInt64(&runCount), ShouldEqual, 0) + assert.Equal(t, atomic.LoadInt64(&runCount), int64(1)) }) + t.Run("Setting a deadline to 0 resets it, function is not executed", func(t *testing.T) { + var runCount int64 + done := make(chan struct{}) + r := NewDeadlineRunner( + func() { + atomic.AddInt64(&runCount, 1) + close(done) + }) + r.SetDeadline(time.Now().Add(10 * time.Millisecond)) + r.SetDeadline(time.Time{}) + time.Sleep(sleepForCallback) + assert.Equal(t, atomic.LoadInt64(&runCount), int64(0)) }) } diff --git a/go/lib/snet/writer_test.go b/go/lib/snet/writer_test.go index f56f2c6ea1..bf389a828b 100644 --- a/go/lib/snet/writer_test.go +++ b/go/lib/snet/writer_test.go @@ -21,9 +21,8 @@ import ( "time" "github.com/golang/mock/gomock" - . "github.com/smartystreets/goconvey/convey" + "github.com/stretchr/testify/assert" - "github.com/scionproto/scion/go/lib/common" "github.com/scionproto/scion/go/lib/mocks/net/mock_net" "github.com/scionproto/scion/go/lib/overlay" "github.com/scionproto/scion/go/lib/pathmgr/mock_pathmgr" @@ -43,141 +42,148 @@ func buildNullMonitorMock(ctrl *gomock.Controller) ctxmonitor.Monitor { } func TestConnRemoteAddressResolver(t *testing.T) { - Convey("Given a remote address resolver", t, func() { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - resolver := &remoteAddressResolver{monitor: buildNullMonitorMock(ctrl)} - Convey("If both addresses are unknown, error out", func() { - address, err := resolver.resolveAddrPair(nil, nil) - SoMsg("err", err, ShouldNotBeNil) - SoMsg("address", address, ShouldBeNil) - }) - Convey("If both address are known, error out", func() { - connRemoteAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") - argRemoteAddress := MustParseAddr("1-ff00:0:110,[127.0.0.1]:80") - address, err := resolver.resolveAddrPair(connRemoteAddress, argRemoteAddress) - SoMsg("err", err, ShouldNotBeNil) - SoMsg("address", address, ShouldBeNil) - }) + t.Log("Given a remote address resolver") + ctrl := gomock.NewController(t) + defer ctrl.Finish() + resolver := &remoteAddressResolver{monitor: buildNullMonitorMock(ctrl)} + t.Run("If both addresses are unknown, error out", func(t *testing.T) { + address, err := resolver.resolveAddrPair(nil, nil) + assert.Error(t, err, "err") + assert.Nil(t, address, "address") + }) + t.Run("If both address are known, error out", func(t *testing.T) { + connRemoteAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") + argRemoteAddress := MustParseAddr("1-ff00:0:110,[127.0.0.1]:80") + address, err := resolver.resolveAddrPair(connRemoteAddress, argRemoteAddress) + assert.Error(t, err, "err") + assert.Nil(t, address, "address") }) } func TestRemoteAddressResolver(t *testing.T) { - Convey("Given a single remote address resolver", t, func() { - ctrl := gomock.NewController(t) - defer ctrl.Finish() - pathSource := mock_pathsource.NewMockPathSource(ctrl) - resolver := &remoteAddressResolver{ - localIA: xtest.MustParseIA("1-ff00:0:110"), - pathResolver: pathSource, - monitor: buildNullMonitorMock(ctrl), - } - Convey("error if address is nil", func() { - address, err := resolver.resolveAddr(nil) - SoMsg("err", common.GetErrorMsg(err), ShouldEqual, ErrAddressIsNil) - SoMsg("address", address, ShouldBeNil) + t.Log("Given a single remote address resolver") + ctrl := gomock.NewController(t) + defer ctrl.Finish() + pathSource := mock_pathsource.NewMockPathSource(ctrl) + resolver := &remoteAddressResolver{ + localIA: xtest.MustParseIA("1-ff00:0:110"), + pathResolver: pathSource, + monitor: buildNullMonitorMock(ctrl), + } + + t.Run("error if address is nil", func(t *testing.T) { + address, err := resolver.resolveAddr(nil) + assert.EqualError(t, err, string(ErrAddressIsNil)) + assert.Nil(t, address, "address") + }) + + t.Run("error if app address is unset", func(t *testing.T) { + address := &Addr{} + address, err := resolver.resolveAddr(address) + assert.EqualError(t, err, string(ErrNoApplicationAddress)) + assert.Nil(t, address, "address") + }) + + t.Run("if destination is in local AS", func(t *testing.T) { + t.Run("error if path set.", func(t *testing.T) { + inAddress := MustParseAddr("1-ff00:0:110,[127.0.0.1]:80") + inAddress.Path = &spath.Path{} + outAddress, err := resolver.resolveAddr(inAddress) + assert.EqualError(t, err, string(ErrExtraPath)) + assert.Nil(t, outAddress, "address") }) - Convey("error if app address is unset", func() { - address := &Addr{} - address, err := resolver.resolveAddr(address) - SoMsg("err", common.GetErrorMsg(err), ShouldEqual, ErrNoApplicationAddress) - SoMsg("address", address, ShouldBeNil) + t.Run("return same address if path unset, and overlay address set.", func(t *testing.T) { + inAddress := MustParseAddr("1-ff00:0:110,[127.0.0.1]:80") + inAddress.NextHop = &overlay.OverlayAddr{} + outAddress, err := resolver.resolveAddr(inAddress) + assert.NoError(t, err, "err") + assert.Equal(t, outAddress, inAddress) }) - Convey("if destination is in local AS", func() { + t.Run("inherit overlay data if overlay address unset.", func(t *testing.T) { inAddress := MustParseAddr("1-ff00:0:110,[127.0.0.1]:80") - Convey("error if path set.", func() { - inAddress.Path = &spath.Path{} - outAddress, err := resolver.resolveAddr(inAddress) - SoMsg("err", common.GetErrorMsg(err), ShouldEqual, ErrExtraPath) - SoMsg("address", outAddress, ShouldBeNil) - }) - Convey("return same address if path unset, and overlay address set.", func() { - inAddress.NextHop = &overlay.OverlayAddr{} - outAddress, err := resolver.resolveAddr(inAddress) - SoMsg("err", err, ShouldBeNil) - SoMsg("address", outAddress, ShouldEqual, inAddress) - }) - Convey("inherit overlay data if overlay address unset.", func() { - outAddress, err := resolver.resolveAddr(inAddress) - SoMsg("err", err, ShouldBeNil) - SoMsg("address", outAddress, ShouldNotBeNil) - SoMsg("overlay addr", outAddress.NextHop.L3(), ShouldResemble, outAddress.Host.L3) - SoMsg("overlay port", outAddress.NextHop.L4(), ShouldResemble, - uint16(overlay.EndhostPort)) - }) + outAddress, err := resolver.resolveAddr(inAddress) + assert.NoError(t, err) + assert.NotNil(t, outAddress) + assert.Equal(t, outAddress.NextHop.L3(), outAddress.Host.L3, "overlay addr") + assert.Equal(t, outAddress.NextHop.L4(), uint16(overlay.EndhostPort), "overlay port") }) - Convey("if destination is not in local AS", func() { + }) + t.Run("if destination is not in local AS", func(t *testing.T) { + t.Run("error if path set but overlay address unset.", func(t *testing.T) { inAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") - Convey("error if path set but overlay address unset.", func() { - inAddress.Path = &spath.Path{} - outAddress, err := resolver.resolveAddr(inAddress) - SoMsg("err", common.GetErrorMsg(err), ShouldEqual, ErrBadOverlay) - SoMsg("address", outAddress, ShouldBeNil) - }) - Convey("error if overlay set but path unset.", func() { - inAddress.NextHop = &overlay.OverlayAddr{} + inAddress.Path = &spath.Path{} + outAddress, err := resolver.resolveAddr(inAddress) + assert.EqualError(t, err, string(ErrBadOverlay)) + assert.Nil(t, outAddress, "address") + }) + t.Run("error if overlay set but path unset.", func(t *testing.T) { + inAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") + inAddress.NextHop = &overlay.OverlayAddr{} + outAddress, err := resolver.resolveAddr(inAddress) + assert.EqualError(t, err, string(ErrMustHavePath)) + assert.Nil(t, outAddress, "address") + }) + t.Run("return same address if path and overlay set.", func(t *testing.T) { + inAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") + inAddress.Path = &spath.Path{} + inAddress.NextHop = &overlay.OverlayAddr{} + outAddress, err := resolver.resolveAddr(inAddress) + assert.NoError(t, err, "err") + assert.Equal(t, outAddress, inAddress) + }) + t.Run("request path if path and overlay unset", func(t *testing.T) { + t.Run("if request not successful, error.", func(t *testing.T) { + inAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") + pathSource.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()). + Return(nil, nil, fmt.Errorf("some error")) outAddress, err := resolver.resolveAddr(inAddress) - SoMsg("err", common.GetErrorMsg(err), ShouldEqual, ErrMustHavePath) - SoMsg("address", outAddress, ShouldBeNil) + assert.EqualError(t, err, string(ErrPath)) + assert.Nil(t, outAddress, "address") }) - Convey("return same address if path and overlay set.", func() { - inAddress.Path = &spath.Path{} - inAddress.NextHop = &overlay.OverlayAddr{} + t.Run("if request successful, return address.", func(t *testing.T) { + inAddress := MustParseAddr("1-ff00:0:113,[127.0.0.1]:80") + path := &spath.Path{} + overlayAddr := &overlay.OverlayAddr{} + pathSource.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()). + Return(overlayAddr, path, nil) outAddress, err := resolver.resolveAddr(inAddress) - SoMsg("err", err, ShouldBeNil) - SoMsg("address", outAddress, ShouldResemble, inAddress) - }) - Convey("request path if path and overlay unset", func() { - Convey("if request not successful, error.", func() { - pathSource.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()). - Return(nil, nil, fmt.Errorf("some error")) - outAddress, err := resolver.resolveAddr(inAddress) - SoMsg("err", common.GetErrorMsg(err), ShouldEqual, ErrPath) - SoMsg("address", outAddress, ShouldBeNil) - }) - Convey("if request successful, return address.", func() { - path := &spath.Path{} - overlayAddr := &overlay.OverlayAddr{} - pathSource.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any()). - Return(overlayAddr, path, nil) - outAddress, err := resolver.resolveAddr(inAddress) - SoMsg("err", err, ShouldBeNil) - SoMsg("address", outAddress, ShouldNotBeNil) - SoMsg("path", outAddress.Path, ShouldEqual, path) - SoMsg("overlay", outAddress.NextHop, ShouldEqual, overlayAddr) - }) + assert.NoError(t, err) + assert.NotNil(t, outAddress) + assert.Equal(t, outAddress.Path, path) + assert.Equal(t, outAddress.NextHop, overlayAddr) }) }) }) } func TestSetDeadline(t *testing.T) { - Convey("Given an snet write connection", t, func() { - ctrl := gomock.NewController(t) - defer ctrl.Finish() + t.Log("Given an snet write connection") + ctrl := gomock.NewController(t) + defer ctrl.Finish() - done := make(chan struct{}, 3) + done := make(chan struct{}, 3) - resolverMock := mock_pathmgr.NewMockResolver(ctrl) - resolverMock.EXPECT().Query(gomock.Any(), gomock.Any(), gomock.Any(), - gomock.Any()).DoAndReturn( + resolverMock := mock_pathmgr.NewMockResolver(ctrl) + resolverMock.EXPECT().Query(gomock.Any(), gomock.Any(), gomock.Any(), + gomock.Any()).DoAndReturn( - func(ctx context.Context, _, _, _ interface{}) spathmeta.AppPathSet { - select { - case <-ctx.Done(): - done <- struct{}{} - } - return nil - }, - ).AnyTimes() - connMock := mock_net.NewMockPacketConn(ctrl) - connMock.EXPECT().SetWriteDeadline(gomock.Any()).AnyTimes().Return(nil) - packetConn := NewSCIONPacketConn(connMock, nil) - - conn := newScionConnWriter(&scionConnBase{ - laddr: MustParseAddr("2-ff00:0:1,[127.0.0.1]:80"), - }, resolverMock, packetConn) - Convey("And writes to multiple destinations for which path resolution is slow", func() { + func(ctx context.Context, _, _, _ interface{}) spathmeta.AppPathSet { + select { + case <-ctx.Done(): + done <- struct{}{} + } + return nil + }, + ).AnyTimes() + connMock := mock_net.NewMockPacketConn(ctrl) + connMock.EXPECT().SetWriteDeadline(gomock.Any()).AnyTimes().Return(nil) + packetConn := NewSCIONPacketConn(connMock, nil) + + conn := newScionConnWriter(&scionConnBase{ + laddr: MustParseAddr("2-ff00:0:1,[127.0.0.1]:80"), + }, resolverMock, packetConn) + t.Run("And writes to multiple destinations for which path resolution is slow", + func(t *testing.T) { addresses := []*Addr{ MustParseAddr("1-ff00:0:1,[127.0.0.1]:80"), MustParseAddr("1-ff00:0:2,[127.0.0.1]:80"), @@ -186,14 +192,13 @@ func TestSetDeadline(t *testing.T) { for _, address := range addresses { go conn.WriteTo([]byte{1, 2, 3}, address) } - Convey("Setting the deadline in the past unlocks all writers", func() { + t.Run("Setting the deadline in the past unlocks all writers", func(t *testing.T) { conn.SetWriteDeadline(time.Now().Add(-time.Second)) for range addresses { xtest.AssertReadReturnsBefore(t, done, time.Second) } }) }) - }) } func MustParseAddr(str string) *Addr {