-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Skip similar networkservices in netsvcmonitor element (#1524)
* fix for issue sdk/1521 Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> * rerun CI Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com> --------- Signed-off-by: NikitaSkrynnik <nikita.skrynnik@xored.com> Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>
- Loading branch information
1 parent
f2a585e
commit 7ad780b
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) 2023 Cisco Systems, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package netsvcmonitor_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"github.com/networkservicemesh/api/pkg/api/registry" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/begin" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/common/netsvcmonitor" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/count" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" | ||
"github.com/networkservicemesh/sdk/pkg/registry/common/memory" | ||
"github.com/networkservicemesh/sdk/pkg/registry/core/adapters" | ||
) | ||
|
||
func Test_Netsvcmonitor_And_GroupOfSimilarNetworkServices(t *testing.T) { | ||
var testCtx, cancel = context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
|
||
var nsServer = memory.NewNetworkServiceRegistryServer() | ||
var nseServer = memory.NewNetworkServiceEndpointRegistryServer() | ||
var counter count.Server | ||
|
||
_, _ = nsServer.Register(context.Background(), ®istry.NetworkService{ | ||
Name: "service-1", | ||
}) | ||
|
||
_, _ = nseServer.Register(context.Background(), ®istry.NetworkServiceEndpoint{ | ||
Name: "endpoint-1", | ||
NetworkServiceNames: []string{"service-1"}, | ||
}) | ||
|
||
var server = chain.NewNetworkServiceServer( | ||
metadata.NewServer(), | ||
begin.NewServer(), | ||
netsvcmonitor.NewServer( | ||
testCtx, | ||
adapters.NetworkServiceServerToClient(nsServer), | ||
adapters.NetworkServiceEndpointServerToClient(nseServer), | ||
), | ||
&counter, | ||
) | ||
|
||
var request = &networkservice.NetworkServiceRequest{ | ||
Connection: &networkservice.Connection{ | ||
Id: "1", | ||
NetworkService: "service-1", | ||
NetworkServiceEndpointName: "endpoint-1", | ||
}, | ||
} | ||
var _, err = server.Request(testCtx, request) | ||
require.NoError(t, err) | ||
require.Equal(t, 0, counter.Closes()) | ||
for i := 0; i < 10; i++ { | ||
_, err = nsServer.Register(context.Background(), ®istry.NetworkService{ | ||
Name: fmt.Sprintf("service-1%v", i), | ||
Matches: []*registry.Match{ | ||
{ | ||
SourceSelector: map[string]string{ | ||
"color": "red", | ||
}, | ||
}, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
} | ||
|
||
require.Never(t, func() bool { | ||
return counter.Closes() > 0 | ||
}, time.Millisecond*300, time.Millisecond*50) | ||
} |