Skip to content

Commit

Permalink
issue #76, #370: add disconnect cleanup test
Browse files Browse the repository at this point in the history
  • Loading branch information
dw committed Nov 1, 2018
1 parent 6bf4d79 commit c148c86
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ansible_mitogen/services.py
Expand Up @@ -268,6 +268,23 @@ def _update_lru(self, new_context, spec, via):
finally:
self._lock.release()

@mitogen.service.expose(mitogen.service.AllowParents())
def dump(self):
"""
For testing, return a list of dicts describing every currently
connected context.
"""
return [
{
'context_name': context.name,
'via': getattr(self._via_by_context.get(context),
'name', None),
'refs': self._refs_by_context.get(context),
}
for context, key in sorted(self._key_by_context.items(),
key=lambda c_k: c_k[0].context_id)
]

@mitogen.service.expose(mitogen.service.AllowParents())
def shutdown_all(self):
"""
Expand Down
1 change: 1 addition & 0 deletions tests/ansible/integration/context_service/all.yml
@@ -1,2 +1,3 @@
- import_playbook: disconnect_cleanup.yml
- import_playbook: lru_one_target.yml
- import_playbook: reconnection.yml
46 changes: 46 additions & 0 deletions tests/ansible/integration/context_service/disconnect_cleanup.yml
@@ -0,0 +1,46 @@
# issue #76, #370: ensure context state is forgotten on disconnect, including
# state of dependent contexts (e.g. sudo, connection delegation, ..).

- name: integration/context_service/disconnect_cleanup.yml
hosts: test-targets
any_errors_fatal: true
tasks:
- meta: end_play
when: not is_mitogen

# Start with a clean slate.
- mitogen_shutdown_all:

# Connect a few users.
- shell: "true"
become: true
become_user: "mitogen__user{{item}}"
with_items: [1, 2, 3]

# Verify current state.
- mitogen_action_script:
script: |
self._connection._connect()
result['dump'] = self._connection.parent.call_service(
service_name='ansible_mitogen.services.ContextService',
method_name='dump'
)
register: out

- assert:
that: out.dump|length == 4 # ssh account + 3 sudo accounts

- meta: reset_connection

# Verify current state.
- mitogen_action_script:
script: |
self._connection._connect()
result['dump'] = self._connection.parent.call_service(
service_name='ansible_mitogen.services.ContextService',
method_name='dump'
)
register: out

- assert:
that: out.dump|length == 1 # just the ssh account

0 comments on commit c148c86

Please sign in to comment.