Skip to content

Commit

Permalink
Set debounceDuration for RemoteOrderSynchronizer to speed up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staskus committed Jan 9, 2025
1 parent 1567cfc commit e25dedd
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,23 @@ final class RemoteOrderSynchronizer: OrderSynchronizer {
///
private var orderSyncTrigger = PassthroughSubject<Order, Never>()

/// The time interval to wait for the next sync request.
///
private let debounceDuration: TimeInterval

// MARK: Initializers


init(siteID: Int64,
flow: EditableOrderViewModel.Flow,
stores: StoresManager = ServiceLocator.stores,
currencySettings: CurrencySettings = ServiceLocator.currencySettings) {
currencySettings: CurrencySettings = ServiceLocator.currencySettings,
debounceDuration: TimeInterval = 1.0) {
self.siteID = siteID
self.stores = stores
self.currencyFormatter = CurrencyFormatter(currencySettings: currencySettings)
self.blockingBehavior = .majorUpdates
self.debounceDuration = debounceDuration

if case let .editing(initialOrder) = flow {
order = initialOrder
Expand Down Expand Up @@ -413,7 +420,7 @@ private extension RemoteOrderSynchronizer {
state = .syncing(blocking: order.containsLocalLines() || order.containsBundleConfigurations())
}
})
.debounce(for: 1.0, scheduler: DispatchQueue.main) // Group & wait for 1.0 since the last signal was emitted.
.debounce(for: .seconds(debounceDuration), scheduler: DispatchQueue.main) // Group & wait for 1.0 since the last signal was emitted.
.map { [weak self] order -> AnyPublisher<Order, Never> in // Allow multiple requests, once per update request.
guard let self = self else { return Empty().eraseToAnyPublisher() }

Expand Down
Loading

0 comments on commit e25dedd

Please sign in to comment.