Skip to content
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

Tests for process tree structure #64

Merged
merged 11 commits into from
Aug 16, 2017
Merged

Tests for process tree structure #64

merged 11 commits into from
Aug 16, 2017

Conversation

JayH5
Copy link
Contributor

@JayH5 JayH5 commented Jul 21, 2017

  • Check the parent PIDs for things
  • Sort processes into master/worker

example/test.py Outdated
for row in ps_rows:
ppid_to_rows.setdefault(row.ppid, []).append(row)

# There should only be to ppids: the parent of the master and the master
Copy link
Member

Choose a reason for hiding this comment

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

"to" -> "two"

Copy link
Member

Choose a reason for hiding this comment

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

Sadly, it wouldn't be sufficiently accurate to write "Always two ppids there are; no more, no less. A master and an apprentice."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah :) I do want a test with multiple Gunicorn "apprentices" at some point.

example/test.py Outdated

assert_tini_pid_1(ps_data.pop(0), 'mysite.wsgi:application')
assert_that(ps_data, HasLength(5))
Copy link
Member

Choose a reason for hiding this comment

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

Why did we need to bring this back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😿 because there isn't anything checking for stray, unknown processes now.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should remove things from the list as we assert on them and then assert that the list is empty at the end?

example/test.py Outdated
nginx_master, nginx_workers = find_prefork_worker_split(nginx_rows)
assert_that(nginx_master, matches_attributes_values(
('ppid', 'ruser', 'args'),
# FIXME: Nginx should not be parented by Gunicorn
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this is because we exec the gunicorn process at the end of our bootstrap script? In that case, everything we run in there will be parented by it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. This is a thing I've known about for a long time, but for the first time it's being tested \o/. I have a branch that sends a SIGKILL to the nginx master process.. and of course the container carries on running happily.

Copy link
Member

@jerith jerith left a comment

Choose a reason for hiding this comment

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

👍 so far. :-)

Copy link
Member

@jerith jerith left a comment

Choose a reason for hiding this comment

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

I'd like to try find a cleaner way to do all these assertions on the process tree.

Maybe we can actually construct a tree (with appropriate filtering) and assert on that? I can take a look and see how hard that might be.

example/test.py Outdated

# There should only be two ppids: the parent of the master and the master
assert len(ppid_to_rows) == 2
Copy link
Member

Choose a reason for hiding this comment

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

Assertions like this aren't very helpful for debugging, because all we know from the failure is that we had a different number of entries from what we're expecting.

@JayH5
Copy link
Contributor Author

JayH5 commented Aug 14, 2017

@jerith: I'm ok with finding better ways so long as they don't take too much time/effort. These are really not very complex trees. And as discussed in #51, I'd actually prefer we didn't encourage running a bunch of things in a single container and had even simpler process trees.

Copy link
Member

@jerith jerith left a comment

Choose a reason for hiding this comment

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

👍 on merging this branch now (after someone who isn't me reviews my recent commit).

I'm happy to review further small things in here before merging if there are any.



class MatchesPsTree(object):
def __init__(self, ruser, args, ppid=None, pid=None, children=()):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it still make sense to have ppid here?

Copy link
Member

Choose a reason for hiding this comment

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

For completeness, I think it does. There's no reason not to have it, and people might want to examine subtrees and assert that the subtree's root has the right ppid.

@JayH5
Copy link
Contributor Author

JayH5 commented Aug 16, 2017

👍 from me on @jerith's changes :)

@JayH5 JayH5 merged commit 2e6e199 into develop Aug 16, 2017
@JayH5 JayH5 deleted the prefork-worker branch August 16, 2017 10:37
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.

2 participants