Skip to content
Open
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
19 changes: 11 additions & 8 deletions interop/scenario_generators/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def insert_new_actor(self, new_actor_name):
if i == len(self.actors):
self.actors.append(new_actor_name)

def commit_and_process(self, committer, proposals):
def commit_and_process(self, committer, proposals, removed = set()):
'''
Committer commits the proposals list, then all actors process.
'''
Expand All @@ -55,18 +55,21 @@ def commit_and_process(self, committer, proposals):

self.actions.append('"action": "commit", "actor": "{}", "byReference": {}'.format(
self.actors[committer],
[prop for prop, sender in proposals if sender != committer],
[prop for prop, sender in proposals],
))

commit_index = len(self.actions) - 1
self.actions.append('"action": "handlePendingCommit", "actor": "{}"'.format(self.actors[committer]))

for actor in range(len(self.actors)):
if actor in removed:
continue

if actor != committer and self.actors[actor] is not None:
self.actions.append('"action": "handleCommit", "actor": "{}", "commit": {}, "byReference": {}'.format(
self.actors[actor],
commit_index,
[prop for prop, sender in proposals if sender != actor],
[prop for prop, sender in proposals],
))
return commit_index

Expand Down Expand Up @@ -97,7 +100,7 @@ def remove_actors(self, committer, removed_actor_indices):
def propose_and_commit(self, committer, proposals, should_succeed=True):
props = []
added_actors = []
removed_indices = []
removed_indices = set()
for proposal, sender, data in proposals:
if proposal == 'add':
new_actor_name = "actor{}".format(self.next_free_actor)
Expand All @@ -107,7 +110,7 @@ def propose_and_commit(self, committer, proposals, should_succeed=True):
proposal_data = ', "keyPackage": {}'.format(len(self.actions)-1)
elif proposal == 'remove':
proposal_data = ', "removed": "{}"'.format(self.actors[data])
removed_indices.append(data)
removed_indices.add(data)
elif proposal == 'update':
proposal_data = ''
elif proposal == 'externalPSK':
Expand All @@ -116,9 +119,9 @@ def propose_and_commit(self, committer, proposals, should_succeed=True):
proposal_data = ', "extensions": {{{}}}'.format(', '.join('"{}": "{}"'.format(k, v) for k, v in data.items()))
props.append((len(self.actions), sender))
self.actions.append('"action": "{}Proposal", "actor": "{}"{}'.format(proposal, self.actors[sender], proposal_data))
commit_index = self.commit_and_process(committer, props)
commit_index = self.commit_and_process(committer, props, removed_indices)
if should_succeed:
for removed in list(collections.OrderedDict.fromkeys(removed_indices)):
for removed in removed_indices:
self.actors[removed] = None
for new_actor_name in list(collections.OrderedDict.fromkeys(added_actors)):
self.insert_new_actor(new_actor_name)
Expand Down Expand Up @@ -164,4 +167,4 @@ def get_json(groups):
header = '{\n "clients": [\n "localhost:50003"\n ],\n "scripts": {\n'
scripts = ','.join(g.get_json() for g in groups)
footer = '\n }\n}'
return header + scripts + footer
return header + scripts + footer