Skip to content

Commit 20fbe1a

Browse files
authored
Defer cleanup flag (#175)
1 parent 5ba89e8 commit 20fbe1a

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

cmd/testrunner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func setupTestCommand() *cobra.Command {
4242
cmd.PersistentFlags().StringSliceP(cobraext.DataStreamsFlagName, "d", nil, cobraext.DataStreamsFlagDescription)
4343
cmd.PersistentFlags().StringP(cobraext.ReportFormatFlagName, "", string(formats.ReportFormatHuman), cobraext.ReportFormatFlagDescription)
4444
cmd.PersistentFlags().StringP(cobraext.ReportOutputFlagName, "", string(outputs.ReportOutputSTDOUT), cobraext.ReportOutputFlagDescription)
45+
cmd.PersistentFlags().DurationP(cobraext.DeferCleanupFlagName, "", 0, cobraext.DeferCleanupFlagDescription)
4546

4647
for _, testType := range testrunner.TestTypes() {
4748
action := testTypeCommandActionFactory(testType)

internal/cobraext/const.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const (
1515
DataStreamsFlagName = "data-streams"
1616
DataStreamsFlagDescription = "comma-separated data streams to test"
1717

18+
DeferCleanupFlagName = "defer-cleanup"
19+
DeferCleanupFlagDescription = "defer test cleanup for debugging purposes"
20+
1821
FailOnMissingFlagName = "fail-on-missing"
1922
FailOnMissingFlagDescription = "fail if tests are missing"
2023

internal/testrunner/runners/pipeline/runner.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,14 @@ func (r *runner) run() ([]testrunner.TestResult, error) {
5757
return nil, errors.Wrap(err, "installing ingest pipelines failed")
5858
}
5959
defer func() {
60+
if r.options.DeferCleanup > 0 {
61+
logger.Debugf("Waiting for %s before cleanup...", r.options.DeferCleanup)
62+
time.Sleep(r.options.DeferCleanup)
63+
}
64+
6065
err := uninstallIngestPipelines(r.options.ESClient, pipelineIDs)
6166
if err != nil {
62-
logger.Warnf("uninstalling ingest pipelines failed: %v", err)
67+
logger.Warnf("Uninstalling ingest pipelines failed: %v", err)
6368
}
6469
}()
6570

internal/testrunner/runners/system/runner.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func Run(options testrunner.TestOptions) ([]testrunner.TestResult, error) {
6767
stackSettings: getStackSettingsFromEnv(),
6868
esClient: options.ESClient,
6969
}
70-
defer r.tearDown()
70+
defer r.tearDown(options)
7171
return r.run()
7272
}
7373

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

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

304301
if r.resetAgentPolicyHandler != nil {

internal/testrunner/testrunner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type TestOptions struct {
3030
PackageRootPath string
3131
GenerateTestResult bool
3232
ESClient *elasticsearch.Client
33+
34+
DeferCleanup time.Duration
3335
}
3436

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

0 commit comments

Comments
 (0)