Skip to content

Commit

Permalink
Merge 9e3c558 into 06ea1a4
Browse files Browse the repository at this point in the history
  • Loading branch information
imkcy9 committed Mar 3, 2020
2 parents 06ea1a4 + 9e3c558 commit b9f649d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/org/zeromq/timer/ZTicket.java
Expand Up @@ -169,7 +169,14 @@ public long timeout()
sortIfNeeded();
// Tickets are sorted, so check first ticket
Ticket first = tickets.get(0);
return first.start - now() + first.delay;
long time = first.start - now() + first.delay;

if (time > 0) {
return time;
}
else {
return 0;
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/zeromq/timer/ZTickerTest.java
Expand Up @@ -11,6 +11,7 @@
import org.junit.Test;
import org.zeromq.timer.ZTicket.Ticket;
import org.zeromq.timer.ZTimer.Timer;
import zmq.ZMQ;

public class ZTickerTest
{
Expand Down Expand Up @@ -68,6 +69,16 @@ public void testTicketInsertion()
assertThat(ticker.timeout(), is(1L));
}

@Test
public void testTicketTimeout()
{
ZTicker ticker = new ZTicker();
Ticket ticket = ticker.addTicket(1, NOOP);
ZMQ.sleep(1);
assertThat(ticket, is(notNullValue()));
assertThat(ticker.timeout(), is(0L));
}

@Test
public void testTimerInsertion()
{
Expand Down

0 comments on commit b9f649d

Please sign in to comment.