Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Commit

Permalink
Adjust timing tolerances for mono
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Oct 25, 2018
1 parent b6c4ed7 commit 0f40396
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/CallPolly/Rules.fs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ type Governor
match config.cutoff with
| None | Some { sla=None; dryRun=false } ->
return! execute
| Some ({ timeout=timeout; sla=sla; dryRun = dryRun } as cutoffConfig)->
| Some ({ timeout=timeout; sla=sla; dryRun = dryRun } as cutoffConfig) ->
try return! execute
finally
if not jitProcessingInterval.IsValueCreated then
Expand Down
8 changes: 4 additions & 4 deletions tests/CallPolly.Acceptance/Scenarios.fs
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ type Scenarios(output : Xunit.Abstractions.ITestOutputHelper) =
let! time, (Status res) = sut.ApiOneSecondSla Succeed (DelayS 5) |> Async.Catch |> Stopwatch.Time
let entries = buffer.Take()
test <@ res = 503
&& between 1. 2. (let t = time.Elapsed in t.TotalSeconds)
&& between 0.9 2. (let t = time.Elapsed in t.TotalSeconds)
&& between 4. 5. (float entries.Length) @> } // 1 api call, 2 call log entries, 1 cutoff event, maybe 1 delayed event

let [<Fact>] ``CallLog - Can capture call-specific log entries isolated from overall log`` () = async {
let callLog, callBuffer = LogHooks.createLoggerWithCapture output
let policy = Parser.parse(policy).CreatePolicy log
let sut = Sut(log, policy)
let! time, (Status res) = sut.ApiOneSecondSlaLog callLog Succeed (DelayS 5) |> Async.Catch |> Stopwatch.Time
test <@ res = 503 && between 1. 2. (let t = time.Elapsed in t.TotalSeconds) @>
test <@ res = 503 && between 0.9 2. (let t = time.Elapsed in t.TotalSeconds) @>
let callEntries, statEntries = callBuffer.Take(), buffer.Take()
test <@ between 1. 2. (float callEntries.Length) // 1 cutoff event, maybe 1 delayed event
test <@ between 0.9 2. (float callEntries.Length) // 1 cutoff event, maybe 1 delayed event
&& 3 = statEntries.Length @> } // 1 api call, 2 call log entries

let [<Fact>] ``Trapping - Arbitrary Polly expressions can be used to define a failure condition`` () = async {
Expand Down Expand Up @@ -271,7 +271,7 @@ type Scenarios(output : Xunit.Abstractions.ITestOutputHelper) =
|> Async.Catch
let! time, res = List.init 1000 alternateBetweenTwoUpstreams |> Async.Parallel |> Stopwatch.Time
let counts = res |> Seq.countBy (function Status s -> s) |> Seq.sortBy fst |> List.ofSeq
test <@ match counts with [200,successCount; 503,rejectCount] -> successCount < 100 && rejectCount > 800 | x -> failwithf "%A" x @>
test <@ match counts with [200,successCount; 503,rejectCount] -> successCount < 200 && rejectCount > 800 | x -> failwithf "%A" x @>
test <@ between 0.3 2.5 (let t = time.Elapsed in t.TotalSeconds) @>
}

Expand Down
14 changes: 7 additions & 7 deletions tests/CallPolly.Tests/RulesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,10 @@ type Limit(output : Xunit.Abstractions.ITestOutputHelper) =
let expectedRules : Rules.BulkheadConfig = { dop = 2; queue = 3; dryRun = false }

let runError = async {
do! Async.Sleep (s 1)
do! Async.Sleep (ms 1000)
return raise (System.TimeoutException()) }
let runOk = async {
do! Async.Sleep (s 1)
do! Async.Sleep (ms 1000)
return 42 }

let [<Fact>] ``dryRun mode does not inhibit processing`` () = async {
Expand All @@ -412,14 +412,14 @@ type Limit(output : Xunit.Abstractions.ITestOutputHelper) =
|> Seq.mapi (fun i f -> async {
// Stagger the starts - the dryRun mode does not force any waiting so wait before we ask for the start so we
// get it into a state where at least 1 start shows queuing would normally take place
do! Async.Sleep(ms (200 * i))
do! Async.Sleep(ms (10 * i))
// Catch inside so the first throw doesnt cancel the overall execution
return! ap.Execute f |> Async.Catch })
|> Async.Parallel
|> Stopwatch.Time
let oks, errs = Choice.partition results
test <@ 3 = Array.length oks
&& time.Elapsed < ms 2500 // 1s+5*200+ 500ms fudge factor
&& time.Elapsed < s 4 // 1000ms*2+5*10+ 1000ms fudge factor
&& 3 = Array.length errs
&& errs |> Seq.forall (fun x -> x.GetType() = typedefof<TimeoutException>) @>
let evnts = buffer.Take()
Expand All @@ -443,7 +443,7 @@ type Limit(output : Xunit.Abstractions.ITestOutputHelper) =
|> Stopwatch.Time
let oks, errs = Choice.partition results
test <@ 5 = Array.length oks
&& time.Elapsed > s 2 && time.Elapsed < s 4
&& time.Elapsed > s 2 && time.Elapsed < s 5 // 1500ms*2+5*200+ 1000ms fudge factor
&& 1 = Array.length errs
&& match Seq.exactlyOne errs with :? Polly.Bulkhead.BulkheadRejectedException -> true | _ -> false @>
let evnts = buffer.Take()
Expand Down Expand Up @@ -496,14 +496,14 @@ type Cutoff(output : Xunit.Abstractions.ITestOutputHelper) =
&& Some { expectedRules with dryRun = true } = ap.Policy.cutoff @>
let r = Random()
let! time, results =
[0 ; 501 ; 1501; 1501; 501; 0]
[0 ; 501 ; 2001; 2001; 501; 0]
|> Seq.mapi (fun i duration -> (if i % 2 = 0 then runError else runOk) (ms duration))
|> Seq.map (ap.Execute >> Async.Catch)
|> Async.Parallel
|> Stopwatch.Time
let oks, errs = Choice.partition results
test <@ 3 = Array.length oks
&& time.Elapsed >= ms 1501 && time.Elapsed < ms 2001 // 1501ms+ 500ms fudge factor
&& time.Elapsed >= ms 2001 && time.Elapsed < ms 5501 // 2001ms*2+ 1.5s fudge factor
&& 3 = Array.length errs
&& errs |> Seq.forall (fun x -> x.GetType() = typeof<TimeoutException>) @>
let evnts = buffer.Take()
Expand Down

0 comments on commit 0f40396

Please sign in to comment.