# Verify that we'll admit in priority order, even if the higher priority work
# has a higher {create time, log position}.

init
----
[regular] 0B tokens available
[elastic] 0B tokens available

# Admit two requests, one at normal-pri but lower {create time, log position}.
admit tenant=t1 pri=normal-pri create-time=1.001us size=1B range=r1 origin=n1 log-position=4/20
----
[regular] try-get=1B available=0B => insufficient tokens

# And one at high-pri but higher {create time, log position}
admit tenant=t1 pri=high-pri create-time=1.002us size=1B range=r1 origin=n1 log-position=4/21
----

# Observe both waiting requests and physical admission stats. Note that the
# high-pri request sorts first, despite having a higher {create time, log
# position}.
print
----
physical-stats: work-count=2 written-bytes=2B ingested-bytes=0B
[regular work queue]: len(tenant-heap)=1 top-tenant=t1
 tenant=t1 weight=1 fifo-threshold=low-pri used=0B
  [0: pri=high-pri create-time=1.002µs size=1B range=r1 origin=n1 log-position=4/21]
  [1: pri=normal-pri create-time=1.001µs size=1B range=r1 origin=n1 log-position=4/20]
[elastic work queue]: len(tenant-heap)=0

# Produce 1B worth of regular tokens.
granter class=regular adjust-tokens=+1B
----
[regular] 1B tokens available
[elastic] 0B tokens available

# Grant admission to requests. Since we have 1B worth of tokens, and 2 waiting
# requests wanting 1B each, we're only able to admit one. Verify that it's the
# high-pri request that gets through.
grant class=regular
----
admitted [tenant=t1 pri=high-pri create-time=1.002µs size=1B range=r1 origin=n1 log-position=4/21]

print
----
physical-stats: work-count=2 written-bytes=2B ingested-bytes=0B
[regular work queue]: len(tenant-heap)=1 top-tenant=t1
 tenant=t1 weight=1 fifo-threshold=low-pri used=1B
  [0: pri=normal-pri create-time=1.001µs size=1B range=r1 origin=n1 log-position=4/20]
[elastic work queue]: len(tenant-heap)=0

# vim:ft=sh
