Skip to content

Defer cleanup flag #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func setupTestCommand() *cobra.Command {
cmd.PersistentFlags().StringSliceP(cobraext.DataStreamsFlagName, "d", nil, cobraext.DataStreamsFlagDescription)
cmd.PersistentFlags().StringP(cobraext.ReportFormatFlagName, "", string(formats.ReportFormatHuman), cobraext.ReportFormatFlagDescription)
cmd.PersistentFlags().StringP(cobraext.ReportOutputFlagName, "", string(outputs.ReportOutputSTDOUT), cobraext.ReportOutputFlagDescription)
cmd.PersistentFlags().DurationP(cobraext.DeferCleanupFlagName, "", 0, cobraext.DeferCleanupFlagDescription)

for _, testType := range testrunner.TestTypes() {
action := testTypeCommandActionFactory(testType)
Expand Down
3 changes: 3 additions & 0 deletions internal/cobraext/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const (
DataStreamsFlagName = "data-streams"
DataStreamsFlagDescription = "comma-separated data streams to test"

DeferCleanupFlagName = "defer-cleanup"
DeferCleanupFlagDescription = "defer test cleanup for debugging purposes"

FailOnMissingFlagName = "fail-on-missing"
FailOnMissingFlagDescription = "fail if tests are missing"

Expand Down
7 changes: 6 additions & 1 deletion internal/testrunner/runners/pipeline/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ func (r *runner) run() ([]testrunner.TestResult, error) {
return nil, errors.Wrap(err, "installing ingest pipelines failed")
}
defer func() {
if r.options.DeferCleanup > 0 {
logger.Debugf("Waiting for %s before cleanup...", r.options.DeferCleanup)
time.Sleep(r.options.DeferCleanup)
}

err := uninstallIngestPipelines(r.options.ESClient, pipelineIDs)
if err != nil {
logger.Warnf("uninstalling ingest pipelines failed: %v", err)
logger.Warnf("Uninstalling ingest pipelines failed: %v", err)
}
}()

Expand Down
13 changes: 5 additions & 8 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Run(options testrunner.TestOptions) ([]testrunner.TestResult, error) {
stackSettings: getStackSettingsFromEnv(),
esClient: options.ESClient,
}
defer r.tearDown()
defer r.tearDown(options)
return r.run()
}

Expand Down Expand Up @@ -292,13 +292,10 @@ func (r *runner) run() ([]testrunner.TestResult, error) {
return resultsWith(result, nil)
}

func (r *runner) tearDown() {
if logger.IsDebugMode() {
// Sleep to give some time for humans to scrutinize the current
// state of the system.
sleepFor := 30 * time.Second
logger.Debugf("waiting for %s before tearing down...", sleepFor)
time.Sleep(sleepFor)
func (r *runner) tearDown(options testrunner.TestOptions) {
if options.DeferCleanup > 0 {
logger.Debugf("waiting for %s before tearing down...", options.DeferCleanup)
time.Sleep(options.DeferCleanup)
}

if r.resetAgentPolicyHandler != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/testrunner/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type TestOptions struct {
PackageRootPath string
GenerateTestResult bool
ESClient *elasticsearch.Client

DeferCleanup time.Duration
}

// RunFunc method defines main run function of a test runner.
Expand Down