DP-3T / dp3t-sdk-backend

The backend implementation for DP3T
Mozilla Public License 2.0
198 stars 88 forks source link

Change how UTCInstant gets Clock #246

Open ubamrein opened 4 years ago

ubamrein commented 4 years ago

For testing purposes it is neat to overwrite the clock of UTCInstant. Currently, the used clock is static, which brings its various problems with it. Also the function setClock overwrites the clock for all future instances, which might lead to unexpected behaviour in case of forgotten resetClock. The latter can be prevented by using the proper Disposable feature of the UTCInstant class.

However, we should overthink the architecture and discuss the issue here, rather than in #215 since it does not pose an immediate risk and should no prevent he PR from merging (it only appears in unit-tests and integration-tests).

ineiti commented 4 years ago

Another code-smell is the fact that static variables are kind of a hidden global variable. And those are never good, because they make it harder to modularize and test things. If for example you want to test clock-skews of different clients, you have to take care that you don't overwrite the clocks from the different clients and the backend.

In addition to that, UTCInstant has a double-function:

The minimum change IMO is to:

This would make sure that nobody calls setClock in the main code.