mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Request Limiter Reload tests (#25126)
This PR introduces a new testonly endpoint for introspecting the RequestLimiter state. It makes use of the endpoint to verify that changes to the request_limiter config are honored across reload. In the future, we may choose to make the sys/internal/request-limiter/status endpoint available in normal binaries, but this is an expedient way to expose the status for testing without having to rush the design. In order to re-use as much of the existing command package utility funcionality as possible without introducing sprawling code changes, I introduced a new server_util.go and exported some fields via accessors. The tests shook out a couple of bugs (including a deadlock and lack of locking around the core limiterRegistry state).
This commit is contained in:
48
command/server_util.go
Normal file
48
command/server_util.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/cli"
|
||||
"github.com/hashicorp/vault/sdk/physical"
|
||||
physInmem "github.com/hashicorp/vault/sdk/physical/inmem"
|
||||
)
|
||||
|
||||
func TestServerCommand(tb testing.TB) (*cli.MockUi, *ServerCommand) {
|
||||
tb.Helper()
|
||||
return testServerCommand(tb)
|
||||
}
|
||||
|
||||
func (c *ServerCommand) StartedCh() chan struct{} {
|
||||
return c.startedCh
|
||||
}
|
||||
|
||||
func (c *ServerCommand) ReloadedCh() chan struct{} {
|
||||
return c.reloadedCh
|
||||
}
|
||||
|
||||
func testServerCommand(tb testing.TB) (*cli.MockUi, *ServerCommand) {
|
||||
tb.Helper()
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
return ui, &ServerCommand{
|
||||
BaseCommand: &BaseCommand{
|
||||
UI: ui,
|
||||
},
|
||||
ShutdownCh: MakeShutdownCh(),
|
||||
SighupCh: MakeSighupCh(),
|
||||
SigUSR2Ch: MakeSigUSR2Ch(),
|
||||
PhysicalBackends: map[string]physical.Factory{
|
||||
"inmem": physInmem.NewInmem,
|
||||
"inmem_ha": physInmem.NewInmemHA,
|
||||
},
|
||||
|
||||
// These prevent us from random sleep guessing...
|
||||
startedCh: make(chan struct{}, 5),
|
||||
reloadedCh: make(chan struct{}, 5),
|
||||
licenseReloadedCh: make(chan error),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user