When a test patches multiple modules with many test cases it can lead to poor performance.
The current lifecycle of patching looks like this.
- On
setup start a Patch.Supervisor with start_supervised which in turn starts the Patch.Listener.Supervisor and Patch.Mock.Supervisor
- For each module that gets patched, start a
Patch.Mock.Server GenServer supervised by the Patch.Mock.Supervisor and then generate the Delegate, Facade and Original modules.
- On
exit the Patch.Supervisor exits and shuts down the Patch.Listener.Supervisor and the Patch.Mock.Supervisor.
- The
Patch.Mock.Supervisor in turn shuts down all the Patch.Mock.Server GenServers.
- Each
Patch.Mock.Server GenServer has a terminate callback which restores the original module by purging the Delegate, Facade, and Original modules and recompiling the true original module.
The above can be quite time intensive, step 2 rewrite the abstract form for the module multiple times, for each patched module there are 4 modules compiled.
Possible higher performance strategy.
- Either globally or on
setup_all start the Patch.Supervisor
- Allow patching to happen normally
- In
setup register an on_exit which resets the internal state of the mock servers (unregister all mocks and reset the history)
This would mean that modules are only recompiled once either during the entire test run or at least a single test case.
When a test patches multiple modules with many test cases it can lead to poor performance.
The current lifecycle of patching looks like this.
setupstart aPatch.Supervisorwithstart_supervisedwhich in turn starts thePatch.Listener.SupervisorandPatch.Mock.SupervisorPatch.Mock.ServerGenServer supervised by thePatch.Mock.Supervisorand then generate theDelegate,FacadeandOriginalmodules.exitthePatch.Supervisorexits and shuts down thePatch.Listener.Supervisorand thePatch.Mock.Supervisor.Patch.Mock.Supervisorin turn shuts down all thePatch.Mock.ServerGenServers.Patch.Mock.ServerGenServer has aterminatecallback which restores the original module by purging theDelegate,Facade, andOriginalmodules and recompiling the true original module.The above can be quite time intensive, step 2 rewrite the abstract form for the module multiple times, for each patched module there are 4 modules compiled.
Possible higher performance strategy.
setup_allstart thePatch.Supervisorsetupregister anon_exitwhich resets the internal state of the mock servers (unregister all mocks and reset the history)This would mean that modules are only recompiled once either during the entire test run or at least a single test case.