# Verify that we ignore create-time based ordering for replicated write
# admission when writes happen within the same range.

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

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

# And one created at t=1us but but higher log position.
admit tenant=t1 pri=normal-pri create-time=1us size=1B range=r1 origin=n1 log-position=4/21
----

# Observe both waiting requests and physical admission stats. Note how the
# request with the lower log position sorts first despite having the higher
# create-time. The StoreWorkQueue sequences them by (ab)using the create-time
# parameter to get this log position ordering.
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=normal-pri create-time=5µs size=1B range=r1 origin=n1 log-position=4/20]
  [1: pri=normal-pri create-time=5.001µs size=1B range=r1 origin=n1 log-position=4/21]
[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
# request with the lower log position despite the higher original create-time.
grant class=regular
----
admitted [tenant=t1 pri=normal-pri create-time=5µs size=1B range=r1 origin=n1 log-position=4/20]

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=5.001µs size=1B range=r1 origin=n1 log-position=4/21]
[elastic work queue]: len(tenant-heap)=0

# vim:ft=sh
