Skip to content

Catch signal while running test runner#277

Merged
mtojek merged 4 commits intoelastic:masterfrom
mtojek:253-ctrl-c
Mar 9, 2021
Merged

Catch signal while running test runner#277
mtojek merged 4 commits intoelastic:masterfrom
mtojek:253-ctrl-c

Conversation

@mtojek
Copy link
Copy Markdown
Contributor

@mtojek mtojek commented Mar 5, 2021

Fixes: #253

This PR modifies the behavior of test runner to catch the signal, so we can cleanup resources while ctrl+c is pressed.

@mtojek mtojek self-assigned this Mar 5, 2021
@mtojek
Copy link
Copy Markdown
Contributor Author

mtojek commented Mar 5, 2021

Hm.. I found another issue:

2021/03/05 15:05:18 ERROR can't tear down the test runner: error cleaning up test policy: could not delete policy; API status code = 500; response body = {"statusCode":500,"error":"Internal Server Error","message":"Cannot delete agent policy that is assigned to agent(s)"}

@ruflin Should it be HTTP 500 or HTTP 4x?

@elasticmachine
Copy link
Copy Markdown
Collaborator

elasticmachine commented Mar 5, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #277 updated

  • Start Time: 2021-03-08T15:13:56.441+0000

  • Duration: 19 min 4 sec

  • Commit: 09116bb

Test stats 🧪

Test Results
Failed 0
Passed 311
Skipped 1
Total 312

Trends 🧪

Image of Build Times

Image of Tests

@mtojek mtojek requested a review from ycombinator March 5, 2021 14:48
@mtojek mtojek marked this pull request as ready for review March 5, 2021 14:48
if err := kib.AssignPolicyToAgent(agent, *policy); err != nil {
return result.WithError(errors.Wrap(err, "could not assign policy to agent"))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curious, why did this block need to be moved?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Assigning a policy is a long operation (due to condition "wait for the policy to get assigned"). If you stop here, but in the mean time an agent gets assigned, you won't be able to delete policy. Just in case it's safer to reassign the original policy.

}
os.Exit(1)
}()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This definitely works so I don't want to block this PR.

But in case some day elastic-package gets more long-running sub-commands, we might want to consider moving this logic to a higher level (not sure where exactly yet) so that a SIGTERM or SIGINT could invoke tear down, if implemented, on that sub command.

BTW, we already have another long-running sub command: elastic-package stack up (without the -d flag). But it looks like SIGINT is already being handled by the underlying lib.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can improve on this in follow-up issues, but this particular one I wanted to focus on improving developer experience of a person writing system tests (and rerunning tests multiple times).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

++ to follow up PRs, as needed.

Copy link
Copy Markdown
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test runner: ctrl+c should tear down the service

3 participants