nim-codex/tests/codex/sales/states
Eric e6a387e8e8
feat[marketplace]: add slot queue pausing (#752)
* add seen flag

* Add MockSlotQueueItem and better prioritisation tests

* Update seen priority, and include in SlotQueueItem.init

* Re-add processed slots to queue

Re-add processed slots to queue if the sale was ignored or errored

* add pausing of queue

- when processing slots in queue, pause queue if item was marked seen
- if availability size is increased, trigger onAvailabilityAdded callback
- in sales, on availability added, clear 'seen' flags, then unpause the queue
- when items pushed to the queue, unpause the queue

* remove unused NoMatchingAvailabilityError from slotqueue

The slot queue should also have nothing to do with availabilities

* when all availabilities are empty, pause the queue

An empty availability is defined as size < DefaultBlockSize as this means even the smallest possible request could not be served. However, this is up for discussion.

* remove availability from onAvailabilitiesEmptied callback

* refactor onAvailabilityAdded and onAvailabilitiesEmptied

onAvailabilityAdded and onAvailabilitiesEmptied are now only called from reservations.update (and eventually reservations.delete once implemented).

- Add empty routine for Availability and Reservation
- Add allEmpty routine for Availability and Reservation, which returns true when all all Availability or Reservation objects in the datastore are empty.

* SlotQueue test support updates

* Sales module test support updates

* Reservations module tests for queue pausing

* Sales module tests for queue pausing

Includes tests for sales states cancelled, errored, ignored to ensure onCleanUp is called with correct parameters

* SlotQueue module tests for queue pausing

* fix existing sales test

* PR feedback

- indent `self.unpause`
- update comment for `clearSeenFlags`

* reprocessSlot in SaleErrored only when coming from downloading

* remove pausing of queue when availabilities are "emptied"

Queue pausing when all availiabilies are "emptied" is not necessary, given that the node would not be able to service slots once all its availabilities' freeSize are too small for the slots in the queue, and would then be paused anyway.

Add test that asserts the queue is paused once the freeSpace of availabilities drops too low to fill slots in the queue.

* Update clearing of seen flags

The asyncheapqueue update overload would need to check index bounds and ultimately a different solution was found using the mitems iterator.

* fix test

request.id was different before updating request.ask.slots, and that id was used to set the state in mockmarket.

* Change filled/cleanup future to nil, so no await is needed

* add wait to allow items to be added to queue

* do not unpause queue when seen items are pushed

* re-add seen item back to queue once paused

Previously, when a seen item was processed, it was first popped off the queue, then the queue was paused waiting to process that item once the queue was unpaused. Now, when a seen item is processed, it is popped off the queue, the queue is paused, then the item is re-added to the queue and the queue will wait until unpaused before it will continue popping items off the queue. If the item was not re-added to the queue, it would have been processed immediately once unpaused, however there may have been other items with higher priority pushed to the queue in the meantime. The queue would not be unpaused if those added items were already seen. In particular, this may happen when ignored items due to lack of availability are re-added to a paused queue. Those ignored items will likely have a higher priority than the item that was just seen (due to it having been processed first), causing the queue to the be paused.

* address PR comments
2024-05-26 00:38:38 +00:00
..
testcancelled.nim feat[marketplace]: add slot queue pausing (#752) 2024-05-26 00:38:38 +00:00
testdownloading.nim feat[marketplace]: add slot queue pausing (#752) 2024-05-26 00:38:38 +00:00
testerrored.nim feat[marketplace]: add slot queue pausing (#752) 2024-05-26 00:38:38 +00:00
testfilled.nim Smart contracts update: Groth16Proof instead of bytes (#683) 2024-02-07 07:50:35 +01:00
testfilling.nim Create memory-leak detecting test suite (#226) 2023-06-22 12:01:21 -06:00
testfinished.nim Create memory-leak detecting test suite (#226) 2023-06-22 12:01:21 -06:00
testignored.nim feat[marketplace]: add slot queue pausing (#752) 2024-05-26 00:38:38 +00:00
testinitialproving.nim Wire up prover (#736) 2024-03-12 12:10:14 +00:00
testpreparing.nim Slot queue (#455) 2023-07-25 12:50:30 +10:00
testproving.nim Fix sales agent (#733) 2024-03-12 06:41:03 +00:00
testsimulatedproving.nim Fix sales agent (#733) 2024-03-12 06:41:03 +00:00
testunknown.nim update asynctest to 0.5.1 (#671) 2024-01-29 17:03:51 -03:00