-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib/limiter composes a maximum simultaneous connections limiter as well as a rate limiter. This commit replaces the connections limiter from oxy with built-in code. Note: this also introduces a bug fix that may change behavior. Prior to this change, the connection limiter kept a separate connection account for HTTP connections than it did for connections managed manually with acquire/release. We no longer maintain separate counts - all connections (HTTP or not) contribute to the number of allowed connections.
- Loading branch information
Showing
6 changed files
with
135 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package limiter_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gravitational/teleport/lib/limiter" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConnectionsLimiter(t *testing.T) { | ||
l, err := limiter.NewConnectionsLimiter(0) | ||
require.NoError(t, err) | ||
|
||
for i := 0; i < 10; i++ { | ||
require.NoError(t, l.AcquireConnection("token1")) | ||
} | ||
for i := 0; i < 5; i++ { | ||
require.NoError(t, l.AcquireConnection("token2")) | ||
} | ||
|
||
for i := 0; i < 10; i++ { | ||
l.ReleaseConnection("token1") | ||
} | ||
for i := 0; i < 5; i++ { | ||
l.ReleaseConnection("token2") | ||
} | ||
|
||
l, err = limiter.NewConnectionsLimiter(5) | ||
require.NoError(t, err) | ||
|
||
for i := 0; i < 5; i++ { | ||
require.NoError(t, l.AcquireConnection("token1")) | ||
} | ||
|
||
for i := 0; i < 5; i++ { | ||
require.NoError(t, l.AcquireConnection("token2")) | ||
} | ||
for i := 0; i < 5; i++ { | ||
require.Error(t, l.AcquireConnection("token2")) | ||
} | ||
|
||
for i := 0; i < 10; i++ { | ||
l.ReleaseConnection("token1") | ||
require.NoError(t, l.AcquireConnection("token1")) | ||
} | ||
|
||
for i := 0; i < 5; i++ { | ||
l.ReleaseConnection("token2") | ||
} | ||
for i := 0; i < 5; i++ { | ||
require.NoError(t, l.AcquireConnection("token2")) | ||
} | ||
} |
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