Skip to content
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

2.x: Pulib constructor for TestScheduler that already takes the time #5901

Closed
vanniktech opened this issue Mar 7, 2018 · 3 comments
Closed

Comments

@vanniktech
Copy link
Collaborator

I'd like to have the ability to have an instantiated TestScheduler which already has a time. Internally it'd just delegate to advanceTimeTo and the constructor would also take the same parameters as that method.

What are your thoughts?

@akarnokd
Copy link
Member

akarnokd commented Mar 7, 2018

You can do it simply after construction:

TestScheduler scheduler = new TestScheduler();
scheduler.advanceTimeBy(System.currentTimeMillis(), TimeUnit.MILLISECONDS);

If this is frequent, just create a static helper method:

public static TestScheduler newTestScheduler(long initialTimeMillis) {
    TestScheduler scheduler = new TestScheduler();
    scheduler.advanceTimeBy(initialTimeMillis, TimeUnit.MILLISECONDS);
    return scheduler;
}

@vanniktech
Copy link
Collaborator Author

vanniktech commented Mar 7, 2018

Yeah with Kotlin it's even easier. I still feel like a constructor that takes the time would be beneficial. I'm not feeling too strong about it so I'll see what the opinions of other folks are.

@akarnokd
Copy link
Member

akarnokd commented Mar 9, 2018

I guess this isn't that of a maintenance intensive change so PR welcome. You could set the current time directly without wasting time by calling advanceTimeBy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants