This adds functionality to ensure that connections are closed on a worker when the server is shut down or reloaded. Connections are closed, and then the shutdown process waits for the next report to the controller to go through, waiting the grace period that was added in #1330. The rest of shutdown is then proceeded with. Listener shutdown has been moved to the start of the process to ensure that new connections can't be made while we are shutting down. Additionally, functionality has been added to force shut down servers after a second interrupt has been received after the first one. This takes the form of code in both the server and dev mode code paths that just performs an os.Exit if another shutdown is received during the normal shutdown process. Additionally, the commit also includes some refactoring to tests so that we could use some of the new E2E testing code to test session connections during shutdown and reload. Additionally, this fixes a panic in worker startup when there are no controllers defined. Looks like the shutdown call was attempting to call into the controller, not the worker. Finally, this also removes the extra shutdown within the outer worker startup. Shutdown is actually handled within the inner StartWorker(), attempting shutdown on errors was actually leading to potential use of an uninitialized worker, which is leading to panics in testing.
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary/internal/cmd/base"
|
|
"github.com/hashicorp/boundary/internal/cmd/config"
|
|
"github.com/hashicorp/boundary/internal/servers/controller"
|
|
"github.com/mitchellh/cli"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// We try to pull these from TestController, but targets et al are
|
|
// computed off of a suffix instead of having constants. Just define
|
|
// for now here, this can be tweaked later if need be.
|
|
const defaultTestTargetId = "ttcp_1234567890"
|
|
|
|
const rootKmsConfig = `
|
|
kms "aead" {
|
|
purpose = "root"
|
|
aead_type = "aes-gcm"
|
|
key = "%s"
|
|
key_id = "global_root"
|
|
}`
|
|
|
|
type testServerCommandOpts struct {
|
|
// Whether or not to create the dev database
|
|
CreateDevDatabase bool
|
|
|
|
// The controller key used in dev database creation
|
|
ControllerKey string
|
|
|
|
// Use the well-known dev mode auth method id (1234567890)
|
|
UseDevAuthMethod bool
|
|
|
|
// Use the well-known dev mode target method id (1234567890)
|
|
UseDevTarget bool
|
|
}
|
|
|
|
func testServerCommand(t *testing.T, opts testServerCommandOpts) *Command {
|
|
require := require.New(t)
|
|
t.Helper()
|
|
cmd := &Command{
|
|
Server: base.NewServer(base.NewCommand(cli.NewMockUi())),
|
|
SighupCh: base.MakeSighupCh(),
|
|
startedCh: make(chan struct{}),
|
|
reloadedCh: make(chan struct{}, 5),
|
|
}
|
|
|
|
require.NoError(cmd.SetupLogging("trace", "", "", ""))
|
|
require.NoError(cmd.SetupEventing(cmd.Logger, cmd.StderrLock, "test-server-command"))
|
|
|
|
if opts.CreateDevDatabase {
|
|
kmsHcl := fmt.Sprintf(rootKmsConfig, opts.ControllerKey)
|
|
parsedKmsConfig, err := config.Parse(kmsHcl)
|
|
require.NoError(err)
|
|
require.NoError(cmd.SetupKMSes(cmd.UI, parsedKmsConfig))
|
|
|
|
if opts.UseDevAuthMethod {
|
|
cmd.Server.DevPasswordAuthMethodId = controller.DefaultTestPasswordAuthMethodId
|
|
cmd.Server.DevLoginName = controller.DefaultTestLoginName
|
|
cmd.Server.DevPassword = controller.DefaultTestPassword
|
|
}
|
|
|
|
if opts.UseDevTarget {
|
|
cmd.Server.DevTargetId = defaultTestTargetId
|
|
}
|
|
|
|
err = cmd.CreateDevDatabase(cmd.Context, base.WithContainerImage("postgres"), base.WithSkipOidcAuthMethodCreation())
|
|
if err != nil {
|
|
if cmd.DevDatabaseCleanupFunc != nil {
|
|
require.NoError(cmd.DevDatabaseCleanupFunc())
|
|
}
|
|
require.NoError(err)
|
|
}
|
|
}
|
|
|
|
return cmd
|
|
}
|