Skip to content

Commit

Permalink
Revert "Add peer cleanup on Requests and Closes from begin (#1636)"
Browse files Browse the repository at this point in the history
This reverts commit c01f9e1.
  • Loading branch information
denis-tingaikin committed Jul 3, 2024
1 parent e3eed82 commit 7ea3b3d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 146 deletions.
2 changes: 0 additions & 2 deletions pkg/networkservice/common/begin/event_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/edwarnicke/serialize"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"google.golang.org/grpc"
"google.golang.org/grpc/peer"

"github.com/networkservicemesh/sdk/pkg/tools/extend"
"github.com/networkservicemesh/sdk/pkg/tools/postpone"
Expand Down Expand Up @@ -180,7 +179,6 @@ func (f *eventFactoryServer) updateContext(valueCtx context.Context) {
f.ctxFunc = func() (context.Context, context.CancelFunc) {
eventCtx, cancel := f.initialCtxFunc()
eventCtx = extend.WithValuesFromContext(eventCtx, valueCtx)
eventCtx = peer.NewContext(eventCtx, &peer.Peer{})
return withEventFactory(eventCtx, f), cancel
}
}
Expand Down
86 changes: 1 addition & 85 deletions pkg/networkservice/common/mechanisms/recvfd/server_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2021-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
// Copyright (c) 2023 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand All @@ -27,9 +27,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"runtime"
"sync"
"testing"
"time"

Expand All @@ -38,8 +36,6 @@ import (
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/common"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.uber.org/goleak"
"google.golang.org/grpc"
Expand All @@ -51,8 +47,6 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkcontext"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkcontextonreturn"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/inject/injecterror"
"github.com/networkservicemesh/sdk/pkg/tools/grpcfdutils"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
"github.com/networkservicemesh/sdk/pkg/tools/sandbox"
Expand Down Expand Up @@ -226,81 +220,3 @@ func (s *checkRecvfdTestSuite) TestRecvfdClosesMultipleFiles() {
}, time.Second, time.Millisecond*100)
}
}

func TestRecvfdDoesntWaitForAnyFilesOnRequestsFromBegin(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)

t.Cleanup(func() {
cancel()
goleak.VerifyNone(t)
})

eventFactoryCh := make(chan begin.EventFactory, 1)
var once sync.Once
// Create a server
server := chain.NewNetworkServiceServer(
begin.NewServer(),
checkcontextonreturn.NewServer(t, func(t *testing.T, ctx context.Context) {
once.Do(func() {
eventFactoryCh <- begin.FromContext(ctx)
close(eventFactoryCh)
})
}),
recvfd.NewServer(),
injecterror.NewServer(
injecterror.WithError(errors.New("error")),
injecterror.WithRequestErrorTimes(1),
injecterror.WithCloseErrorTimes(1)),
)

tempDir := t.TempDir()
sock, err := os.Create(filepath.Clean(path.Join(tempDir, "test.sock")))
require.NoError(t, err)

serveURL := &url.URL{Scheme: "unix", Path: sock.Name()}
grpcServer := grpc.NewServer(grpc.Creds(grpcfd.TransportCredentials(insecure.NewCredentials())))
networkservice.RegisterNetworkServiceServer(grpcServer, server)
errCh := grpcutils.ListenAndServe(ctx, serveURL, grpcServer)
require.Len(t, errCh, 0)

// Create a client
c := createClient(ctx, serveURL)

// Create a file to send
testFileName := filepath.Clean(path.Join(tempDir, "TestRecvfdDoesntWaitForAnyFilesOnRequestsFromBegin.test"))
f, err := os.Create(testFileName)
require.NoErrorf(t, err, "Failed to create and open a file: %v", err)
err = f.Close()
require.NoErrorf(t, err, "Failed to close file: %v", err)

// Create a request
request := &networkservice.NetworkServiceRequest{
Connection: &networkservice.Connection{
Id: "id",
Mechanism: &networkservice.Mechanism{
Cls: cls.LOCAL,
Type: kernel.MECHANISM,
Parameters: map[string]string{
common.InodeURL: "file:" + testFileName,
},
},
},
}

// Make the first request from the client to send files
conn, err := c.Request(ctx, request)
require.NoError(t, err)
request.Connection = conn.Clone()

// Make the second request that return an error.
// It should make recvfd close all the files.
_, err = c.Request(ctx, request)
require.Error(t, err)

// Send Close. Recvfd shouldn't freeze trying to read files
// from the client because we send Close from begin.
eventFactory := <-eventFactoryCh
ch := eventFactory.Close()
err = <-ch
require.NoError(t, err)
}
59 changes: 0 additions & 59 deletions pkg/networkservice/utils/checks/checkcontextonreturn/server.go

This file was deleted.

0 comments on commit 7ea3b3d

Please sign in to comment.