mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 11:45:49 +01:00
Fix Timer.isRunning() returning true immediately after rescheduling (#4313)
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
parent
918b4faa3b
commit
8cc267afd8
@ -30,7 +30,6 @@ import org.openhab.core.scheduler.SchedulerRunnable;
|
||||
public class TimerImpl implements Timer {
|
||||
|
||||
private final Scheduler scheduler;
|
||||
private final ZonedDateTime startTime;
|
||||
private final SchedulerRunnable runnable;
|
||||
private final @Nullable String identifier;
|
||||
private ScheduledCompletableFuture<?> future;
|
||||
@ -42,7 +41,6 @@ public class TimerImpl implements Timer {
|
||||
public TimerImpl(Scheduler scheduler, ZonedDateTime startTime, SchedulerRunnable runnable,
|
||||
@Nullable String identifier) {
|
||||
this.scheduler = scheduler;
|
||||
this.startTime = startTime;
|
||||
this.runnable = runnable;
|
||||
this.identifier = identifier;
|
||||
|
||||
@ -78,7 +76,7 @@ public class TimerImpl implements Timer {
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return isActive() && ZonedDateTime.now().isAfter(startTime);
|
||||
return isActive() && ZonedDateTime.now().isAfter(future.getScheduledTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -111,6 +111,12 @@ public class TimerImplTest {
|
||||
assertThat(subject.isRunning(), is(false));
|
||||
assertThat(subject.hasTerminated(), is(true));
|
||||
assertThat(subject.isCancelled(), is(false));
|
||||
|
||||
subject.reschedule(ZonedDateTime.now().plusSeconds(DEFAULT_TIMEOUT_SECONDS));
|
||||
assertThat(subject.isRunning(), is(false));
|
||||
|
||||
Thread.sleep(TimeUnit.SECONDS.toMillis(DEFAULT_TIMEOUT_SECONDS) + 500);
|
||||
assertThat(subject.isRunning(), is(true));
|
||||
}
|
||||
|
||||
private Timer createTimer(ZonedDateTime instant, SchedulerRunnable runnable) {
|
||||
|
Loading…
Reference in New Issue
Block a user