-
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.
[sdk#1028] Fix Timeout, Expire to handle failed Close, Unregister (#1030
) * Fix timeout to handle failed Close Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix expire to handle failed Unregister Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Add registry injecterror package Signed-off-by: Vladimir Popov <vladimir.popov@xored.com> * Fix expire tests with injecterror Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
- Loading branch information
Vladimir Popov
authored
Jul 20, 2021
1 parent
b086a10
commit 0602401
Showing
10 changed files
with
430 additions
and
81 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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 injecterror provides chain elements returning given error on Register, Unregister on given times | ||
package injecterror |
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,42 @@ | ||
// Copyright (c) 2020-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 injecterror | ||
|
||
type errorSupplier struct { | ||
err error | ||
count int | ||
errorTimes []int | ||
} | ||
|
||
// supply returns an error or nil depending on errorTimes | ||
// * [0, 2, 3] - will return an error on 0, 2, 3 times | ||
// * [-1] - will return an error on all requests | ||
// * [1, 4, -1] - will return an error on 0 time and on all times starting from 4 | ||
func (e *errorSupplier) supply() error { | ||
defer func() { e.count++ }() | ||
|
||
for _, errorTime := range e.errorTimes { | ||
if errorTime > e.count { | ||
break | ||
} | ||
if errorTime == e.count || errorTime == -1 { | ||
return e.err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.