-
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.
Add heal elements into client chain (#945)
* fix panic in authorize client Signed-off-by: Danil Uzlov <DanilUzlov@yandex.ru> * move client factory interface into connect package Signed-off-by: Danil Uzlov <DanilUzlov@yandex.ru> * add standalone client function with heal support Signed-off-by: Danil Uzlov <DanilUzlov@yandex.ru> * fix review Signed-off-by: Artem Glazychev <artem.glazychev@xored.com> * add nsmgr test Signed-off-by: Artem Glazychev <artem.glazychev@xored.com> Co-authored-by: Artem Glazychev <artem.glazychev@xored.com>
- Loading branch information
1 parent
06aafeb
commit 7b63239
Showing
8 changed files
with
196 additions
and
66 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,80 @@ | ||
// Copyright (c) 2021 Doc.ai and/or its affiliates. | ||
// | ||
// 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 client_test | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.uber.org/goleak" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/client" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint" | ||
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils" | ||
"github.com/networkservicemesh/sdk/pkg/tools/sandbox" | ||
) | ||
|
||
func TestClientHeal(t *testing.T) { | ||
t.Cleanup(func() { goleak.VerifyNone(t) }) | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
||
serverURL := &url.URL{Scheme: "tcp", Host: "127.0.0.1:0"} | ||
serverCancel := startEmptyServer(ctx, t, serverURL) | ||
defer serverCancel() | ||
|
||
nsc := client.NewClient(ctx, | ||
serverURL, | ||
client.WithDialOptions(sandbox.DefaultDialOptions(sandbox.GenerateTestToken)...), | ||
client.WithDialTimeout(time.Second), | ||
) | ||
_, err := nsc.Request(ctx, &networkservice.NetworkServiceRequest{}) | ||
require.NoError(t, err) | ||
|
||
serverCancel() | ||
require.Eventually(t, func() bool { | ||
return grpcutils.CheckURLFree(serverURL) | ||
}, time.Second, time.Millisecond*10) | ||
require.NoError(t, ctx.Err()) | ||
|
||
serverCancel = startEmptyServer(ctx, t, serverURL) | ||
defer serverCancel() | ||
|
||
require.Eventually(t, func() bool { | ||
_, err = nsc.Request(ctx, &networkservice.NetworkServiceRequest{}) | ||
return err == nil | ||
}, time.Second*2, time.Millisecond*50) | ||
} | ||
|
||
func startEmptyServer(ctx context.Context, t *testing.T, serverURL *url.URL) context.CancelFunc { | ||
serverCtx, serverCancel := context.WithCancel(ctx) | ||
|
||
nse := endpoint.NewServer(serverCtx, sandbox.GenerateTestToken) | ||
|
||
select { | ||
case err := <-endpoint.Serve(serverCtx, serverURL, nse): | ||
require.NoError(t, err) | ||
default: | ||
} | ||
|
||
return serverCancel | ||
} |
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
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
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
Oops, something went wrong.