Skip to content
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
13 changes: 13 additions & 0 deletions internal/signal/sigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/elastic/elastic-package/internal/logger"
)
Expand All @@ -30,3 +31,15 @@ func SIGINT() bool {
return false
}
}

// Sleep is the equivalent of time.Sleep with the exception
// that is will end the sleep if ctrl+c is pressed.
func Sleep(d time.Duration) {
timer := time.NewTimer(d)
select {
case <-ch:
logger.Info("Signal caught!")
timer.Stop()
case <-timer.C:
}
}
3 changes: 2 additions & 1 deletion internal/testrunner/runners/pipeline/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/elastic/elastic-package/internal/logger"
"github.com/elastic/elastic-package/internal/multierror"
"github.com/elastic/elastic-package/internal/packages"
"github.com/elastic/elastic-package/internal/signal"
"github.com/elastic/elastic-package/internal/testrunner"
)

Expand Down Expand Up @@ -58,7 +59,7 @@ func (r *runner) Run(options testrunner.TestOptions) ([]testrunner.TestResult, e
func (r *runner) TearDown() error {
if r.options.DeferCleanup > 0 {
logger.Debugf("Waiting for %s before cleanup...", r.options.DeferCleanup)
time.Sleep(r.options.DeferCleanup)
signal.Sleep(r.options.DeferCleanup)
}

err := uninstallIngestPipelines(r.options.API, r.pipelines)
Expand Down
3 changes: 1 addition & 2 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (r *runner) TearDown() error {
func (r *runner) tearDownTest() error {
if r.options.DeferCleanup > 0 {
logger.Debugf("waiting for %s before tearing down...", r.options.DeferCleanup)
time.Sleep(r.options.DeferCleanup)
signal.Sleep(r.options.DeferCleanup)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so I see that this is enabled only for options.DeferCleanup? If so, then I guess it's safe to merge.

}

if r.resetAgentPolicyHandler != nil {
Expand Down Expand Up @@ -437,7 +437,6 @@ func (r *runner) runTest(config *testConfig, ctxt servicedeployer.ServiceContext
docs, err = r.getDocs(dataStream)
return len(docs) > 0, err
}, waitForDataTimeout)

if err != nil {
return result.WithError(err)
}
Expand Down