Module em_module_loader

INTERNAL MODULE Load modules on behalf of the em module.

Copyright © (C) 2018,2021 Sven Heyll

Behaviours: gen_statem.

Authors: Sven Heyll (sven@wega.lbaum.eu).

Description

INTERNAL MODULE Load modules on behalf of the em module.

A story why we need this:

Stardate "Feburary 2018". We have a Heisenbug in the unit test execution introduced in version 7.0.0.

After narrowing it down to code loading race conditions, We failed to fix the problem by using global:set_lock around critical sections. Also, we don't know why.

This module is an attempt to answer to the situation.

Q: When the em process manages loading and restoring the mocking and original code, what happens if the em process gets killed after loading a module, and a process tries to execute functions from that module?

See this code:
   -module(yolo_tests).
   ...
   killing_the_mock_test() ->
      M = em:new(),
      em:strict(M, foo, aaaa, [],
                {function, fun(_) -> exit(kill) end}),
      em:replay(M),
      ?assertEqual(test_result,
                   yolo:do_aaaa_with_foo()),
  
      em:verify(M).
  
   simple_test() ->
      ?assertEqual(ok, yolo:just_do_it()).
   
The implementation:
   -module(yolo).
   -behaviour(gen_server).
   ...
   just_do_it() ->
       foo:do_just_it(),
       ok.
  
   do_aaaa_with_foo() ->
       foo:aaaa().
   
Without another server that cares about loading and unloading the modules, there is no way the test above can be fixed without removing the brutal kill in the strict callback.

Function Index

disable_module_loading/0
enable_module_loading/0
load_modules/2
restore_modules/0
start/0

Function Details

disable_module_loading/0

disable_module_loading() -> ok | error

enable_module_loading/0

enable_module_loading() -> ok | error

load_modules/2

load_modules(Modules::[{module(), file:filename(), binary()}], Timeout::gen_statem:timeout()) -> ok | error

restore_modules/0

restore_modules() -> ok | error

start/0

start() -> ok


Generated by EDoc