mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-03 14:03:10 +00:00
* fix(sales): handle cancellation of slot cleanup Ensures that processing slots from the slot queue continues even when cleanup of a slot is cancelled. Co-Authored-By: Eric <5089238+emizzle@users.noreply.github.com> * chore(reservations): add more `raises` annotations * Fix cleanup cancellation * Add remove-agent to trackedfutures instead of the cleanup function * Increase the timeout to match the request expiry * Enable logs to debug on CI * Remove useless except and do not return when add item back to slot queue fails * Reduce poll interval to detect sale cancelled state * Avoid cancelling cleanup routine * Do not cancel creating reservation in order to avoid inconsistent state * Remove useless try except --------- Co-authored-by: Mark Spanbroek <mark@spanbroek.net> Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com>
52 lines
1.5 KiB
Nim
52 lines
1.5 KiB
Nim
import pkg/chronos
|
|
import pkg/codex/sales
|
|
import pkg/codex/stores
|
|
import pkg/questionable/results
|
|
import pkg/codex/clock
|
|
|
|
type MockReservations* = ref object of Reservations
|
|
createReservationThrowBytesOutOfBoundsError: bool
|
|
createReservationThrowError: ?(ref CatchableError)
|
|
|
|
proc new*(T: type MockReservations, repo: RepoStore): MockReservations =
|
|
## Create a mock clock instance
|
|
MockReservations(availabilityLock: newAsyncLock(), repo: repo)
|
|
|
|
proc setCreateReservationThrowBytesOutOfBoundsError*(
|
|
self: MockReservations, flag: bool
|
|
) =
|
|
self.createReservationThrowBytesOutOfBoundsError = flag
|
|
|
|
proc setCreateReservationThrowError*(
|
|
self: MockReservations, error: ?(ref CatchableError)
|
|
) =
|
|
self.createReservationThrowError = error
|
|
|
|
method createReservation*(
|
|
self: MockReservations,
|
|
availabilityId: AvailabilityId,
|
|
slotSize: uint64,
|
|
requestId: RequestId,
|
|
slotIndex: uint64,
|
|
collateralPerByte: UInt256,
|
|
validUntil: SecondsSince1970,
|
|
): Future[?!Reservation] {.async: (raises: [CancelledError]).} =
|
|
if self.createReservationThrowBytesOutOfBoundsError:
|
|
let error = newException(
|
|
BytesOutOfBoundsError,
|
|
"trying to reserve an amount of bytes that is greater than the total size of the Availability",
|
|
)
|
|
return failure(error)
|
|
elif error =? self.createReservationThrowError:
|
|
return failure(error)
|
|
|
|
return await procCall createReservation(
|
|
Reservations(self),
|
|
availabilityId,
|
|
slotSize,
|
|
requestId,
|
|
slotIndex,
|
|
collateralPerByte,
|
|
validUntil,
|
|
)
|