Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: denis-tingaikin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin committed Jun 29, 2024
1 parent 7116f73 commit c73a1cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pkg/networkservice/common/netsvcmonitor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (m *monitorServer) Request(ctx context.Context, request *networkservice.Net

for _, seg := range resp.GetPath().GetPathSegments() {
var t = seg.Expires.AsTime().Local()
if minT.Before(t) || minT.IsZero() {
if minT.After(t) || minT.IsZero() {
minT = t
}
}
Expand Down
32 changes: 6 additions & 26 deletions pkg/networkservice/common/netsvcmonitor/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ func Test_Netsvcmonitor_And_GroupOfSimilarNetworkServices(t *testing.T) {
}

func Test_NetsvcMonitor_ShouldNotLeakWithoutClose(t *testing.T) {
var testCtx, cancel = context.WithTimeout(context.Background(), time.Second*5)
t.Cleanup(func() {
goleak.VerifyNone(t)
require.Eventually(t, func() bool {
return goleak.Find(goleak.IgnoreAnyFunction("github.com/stretchr/testify/assert.Eventually")) == nil
}, time.Second*2, time.Second/10)
cancel()
})

var testCtx, cancel = context.WithCancel(context.Background())
defer cancel()

var nsServer = memory.NewNetworkServiceRegistryServer()
var nseServer = memory.NewNetworkServiceEndpointRegistryServer()
var counter count.Server
Expand All @@ -130,8 +130,6 @@ func Test_NetsvcMonitor_ShouldNotLeakWithoutClose(t *testing.T) {
&counter,
)

var n = time.Now().Add(time.Second)

var request = &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{
Id: "1",
Expand All @@ -140,7 +138,7 @@ func Test_NetsvcMonitor_ShouldNotLeakWithoutClose(t *testing.T) {
Path: &networkservice.Path{
PathSegments: []*networkservice.PathSegment{
{
Expires: timestamppb.New(n),
Expires: timestamppb.New(time.Now().Add(time.Second)),
},
},
},
Expand All @@ -149,22 +147,4 @@ func Test_NetsvcMonitor_ShouldNotLeakWithoutClose(t *testing.T) {

var _, err = server.Request(testCtx, request)
require.NoError(t, err)

for end := time.Now().Add(time.Second); time.Now().Before(end); time.Sleep(time.Millisecond * 100) {
if goleak.Find() != nil {
break
}
}
if goleak.Find() == nil {
require.FailNow(t, "netsvc goroutine must be created")
}

for end := time.Now().Add(time.Second * 2); time.Now().Before(end); time.Sleep(time.Millisecond * 100) {
if goleak.Find() == nil {
break
}
}
if e := goleak.Find(); e != nil {
require.FailNow(t, "netsvc goroutine must be stopped, but it's found"+e.Error())
}
}

0 comments on commit c73a1cc

Please sign in to comment.