Skip to content

stateful modifier expressions - #54

Open
gijsvcuyck wants to merge 3 commits into
JFoederer:mainfrom
gijsvcuyck:assign_during_mod
Open

gijsvcuyck wants to merge 3 commits into
JFoederer:mainfrom
gijsvcuyck:assign_during_mod

Conversation

@gijsvcuyck

Copy link
Copy Markdown
Contributor

The problem

Modifier expressions do not work well when a constraint describing the desired equivalence class needs the value of another variable affected by a modifier expression. In the following scenario, it is therefore not possible to apply a modifier expression over both Alice and Bob at the same time effectively. If done anyway, this increases the trace generation time, sometimes to the point of not finding a trace, because many generated instances of the scenario will be rejected.

Friends can pass messages
  Given Alice and Bob are friends
  When Alice sends a message to Bob
  Then Bob receives a message

The problem is that modifiers are resolved one at a time, and cannot access the values chosen by any of the other modifiers.
This makes it possible to select two people for the variables Alice and Bob such that both people have a friend, but it is not possible to select two people such that they are friends with each other.

A solution

A comprehensive solution to this problem would be complicated and require a substantial rewrite to the modifier system.
Instead, this PR makes some minimal changes to allow for a workaround: stateful modifier expressions.

Modifier expressions can now make variable assignments to scenario variables, which are accessible by all other modifier steps in the same scenario.
To resolve the problem above, the following modifier expression could be used for the step Given Alice and Bob are friends:

:MOD: scenario.user = __import__('random').choice([person for person in People.everyone if len(person.friends) > 0])
                        ${user1} = [scenario.user]
                        ${user2} = scenario.user.friends

This example resolves all variables in one step, but any following step can base further modifier expressions on the value chosen for the first user by accessing scenario.user.

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.

1 participant