-
Notifications
You must be signed in to change notification settings - Fork 706
Added a class to abstract time to a centralised place to improve testing. #483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Added a class to abstract time to a centralised place to improve testing. #483
Conversation
b8acd84
to
00927cc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're on the right track with removing System.currentTimeMillis, but it should be replaced directly with Java.time.Clock which then can be manipulated directly in tests.
* allow for interacting with time during testing. | ||
*/ | ||
public class TimeService { | ||
public static boolean useCustomClockForTests = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally classes shouldn't know about how they're used, especially with relation to testing.
There are also places in Conductor which invoke Instant.now(), LocalDate.now() etc. |
Yeah, I missed it actually 😓 . I will cover them as well
We have a use case in which we want to manipulate time during testing in one of our service which uses conductor-oss as self hosted orchestration engine. We want to use custom clock which is shared across all the direct dependencies in service, that is conductor, queue etc. This clock then be used to manipulate time. This is mainly be used in integration tests. |
Yes, but there are some problem to that. |
I think overall this is a good idea. The approach I think that makes sense here is as the following:
|
Pull Request type
NOTE: Please remember to run
./gradlew spotlessApply
to fix any format violations.Changes in this PR
We have a use case where we need to change time during execution of integration tests. This is an attempt to abstract out the time in conductor to a single place, so that during testing we can manipulate the time as per the need.
Describe the new behavior from this PR, and why it's needed
Issue #482
This PR adds a service to fetch current time in conductor via static methods. These methods can be overriden in tests to manipulate time.
Alternatives considered
I also thought of using Bean (via @bean config) to return clock instance or having TimeService as a
Component
but that would then require injecting the clock or TimeService into different classes which fetch current time. This breaks the backward compatibility and hence rejected those options.