Skip to content

Commit

Permalink
Clean batching test to match V2 doc per Transact
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Oct 10, 2019
1 parent 0df11b6 commit 4c1686c
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions tests/Equinox.Cosmos.Integration/CosmosIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ open Equinox.Cosmos
open Equinox.Cosmos.Integration.Infrastructure
open FSharp.UMX
open Swensen.Unquote
open System.Threading
open System
open System.Threading

module Cart =
let fold, initial = Domain.Cart.Folds.fold, Domain.Cart.Folds.initial
Expand Down Expand Up @@ -79,34 +79,30 @@ type Tests(testOutputHelper) =
let! conn = connectToSpecifiedCosmosOrSimulator log

let maxItemsPerRequest = 2
let maxEventsPerBatch = 3
let service = Cart.createServiceWithoutOptimization conn maxItemsPerRequest log
capture.Clear() // for re-runs of the test

let cartId = % Guid.NewGuid()
// The command processing should trigger only a single read and a single write call
let addRemoveCount = 2
let eventsPerAction = addRemoveCount * 2 - 1
let batches = 4
for i in [1..batches] do
let transactions = 6
for i in [1..transactions] do
do! addAndThenRemoveItemsManyTimesExceptTheLastOne context cartId skuId service addRemoveCount
let expectedBatchesOf2Items =
match i with
| 1 -> 1 // it does cost a single trip to determine there are 0 items
| i -> ceil(float (i-1) * float eventsPerAction / float maxItemsPerRequest / float maxEventsPerBatch) |> int
test <@ List.replicate expectedBatchesOf2Items EqxAct.ResponseBackward @ [EqxAct.QueryBackward; EqxAct.Append] = capture.ExternalCalls @>
verifyRequestChargesMax 46 // 44.32
// Extra roundtrip required after maxItemsPerRequest is exceeded
let expectedBatchesOf2Items = (i-1) / maxItemsPerRequest + 1
test <@ i = i && List.replicate expectedBatchesOf2Items EqxAct.ResponseBackward @ [EqxAct.QueryBackward; EqxAct.Append] = capture.ExternalCalls @>
verifyRequestChargesMax 48 // 47.29
capture.Clear()

// Validate basic operation; Key side effect: Log entries will be emitted to `capture`
let! state = service.Read cartId
let expectedEventCount = batches * eventsPerAction
let expectedEventCount = transactions * eventsPerAction
test <@ addRemoveCount = match state with { items = [{ quantity = quantity }] } -> quantity | _ -> failwith "nope" @>

// Need 6 trips of 2 maxItemsPerRequest to read 12 events
test <@ let expectedResponses = ceil(float expectedEventCount/float maxItemsPerRequest/float maxEventsPerBatch) |> int
List.replicate expectedResponses EqxAct.ResponseBackward @ [EqxAct.QueryBackward] = capture.ExternalCalls @>
verifyRequestChargesMax 7 // 5.93
let expectedResponses = transactions/maxItemsPerRequest + 1
test <@ List.replicate expectedResponses EqxAct.ResponseBackward @ [EqxAct.QueryBackward] = capture.ExternalCalls @>
verifyRequestChargesMax 12 // 11.8
}

[<AutoData(MaxTest = 2, SkipIfRequestedViaEnvironmentVariable="EQUINOX_INTEGRATION_SKIP_COSMOS")>]
Expand Down

0 comments on commit 4c1686c

Please sign in to comment.