consensus-shipyard / mir

Apache License 2.0
46 stars 14 forks source link

Mock modules #138

Open xosmig opened 2 years ago

xosmig commented 2 years ago

Standard mocking utils like gomock do not really work well with Mir because they only allow setting expectations on method calls while we need to set expectations on the received events and, instead of specifying return values, we should be able to specify output events.

matejpavlovic commented 2 years ago

Does this apply only to ActiveModules, or are PassiveModules (which are defined only in terms of function calls and return values) also problematic?

xosmig commented 2 years ago

In fact, I just realized that there is a simple work-around for passive modules :sweat_smile: The problem with passive modules is the built-in batching: we have to set expectations on ApplyEvents, which may contain several events at once. The work-around is to create an interface with the method ApplyEvent instead of ApplyEvents and mock this interface instead of PassiveModule itself. Then we can wrap the mocked object in order to implement the PassiveModule interface.

Not sure if this solution will be as good as first-class mocking utilities for Mir, but it is probably good enough for now.