Stateful properties and application assigned identifiers

Frans Schneider fchschneider@REDACTED
Wed May 6 10:27:33 CEST 2020


Dear list,

I have an application in which each new entity is assigned a unique id 
(UUID) during runtime. All functions related to such an entity use this 
id as a reference. I am in the process of writing property based tests 
using PropEr using stateful properties. The problem I run into is how to 
handle the system generated ids.

For example, I create something called a policy class with the call 
pm_pap:c_pc(#pc{value=...}). This returns the record #pc{id=<<some 
uuid>>, value=...}. Now, to delete the policy class, the call 
pm_pap:d_pc(Id) is made with the id as returned by the pm_pap:c_pc/1 call.

For the commands/1 and next_state/3 and generator pc() I use something like:

command(#state{pcs = []}) ->
     {call, pm_pap, c_pc, [pc()]};
command(#state{pcs = [PC | _]}) ->
     {call, pm_pap, d_pc, [PC]};
...

next_state(#state{pcs = PCs} = State, _Res, {call, pm_pap, c_pc, [PC]}) ->
     State#state{pcs = [PC | PCs]};
next_state(State, _Res, {call, _Mod, _Fun, _Args}) ->
     NewState = State,
     NewState.

pc() ->
     ?LET(Name, string(), #pc{value = Name}).

During the first phase of the test run, obviously the id's are not yet 
generated because no calls are made to the actual system. Using the PC 
from the state in the command to delete the PC will than of course fail 
because the PC in the state has doesn't have a valid id when the 
symbolic call is created.

The general question I have is how to handle things like dynamic 
generated id's or processes in stateful properties. Does somebody have 
an example of doing this?

Thanks,

Frans



More information about the erlang-questions mailing list