import time

# Send bundles with ID 1-4,6-9 that ION should accept custody of.
timestr = time.strftime("%m/%d/%Y %H:%M:%S", time.gmtime() )
bids = [ ]
for i in range(10):
    sendexpectacsandcustody("ipn:2.0", "ipn:13.42", timestr, i, cid = i, ttl = 5)
    bids.append(("ipn:13.42", dtntime(timestr), i))

# Get the CTEBs that ION assigned to these bundles when it forwarded them.
receiveuntil(3.0)

# Verify that ION accepted custody of these bundles
checkcustody()

# Wait for bundles to exceed TTL and be expired.
sleep(6.0)

# Send ION an ACS for the expired bundle anyway.
sendacs("ipn:1.0", bids)
sleep(0.25)

# Our expected custody list should be empty due to expired bundle.
emptycustody()

# Verify that ION released custody of those bundles.
checkcustody()

# Send a bundle again, to make sure our stale ACS didn't crash ION.
sendexpectacsandcustody("ipn:2.0", "ipn:13.42", timestr, 11, cid = 11 )

# Get the CTEBs that ION assigned to these bundles when it forwarded them.
receiveuntil( 2.0 )

# Verify that ION accepted custody of these bundles
checkcustody()

# Clear custody of this extra bundle and verify it is released from ION.
clearcustody("ipn:1.0")
sleep(0.25)
checkcustody()
