diff --git a/src/CallPolly/Rules.fs b/src/CallPolly/Rules.fs index 14121de..3113640 100644 --- a/src/CallPolly/Rules.fs +++ b/src/CallPolly/Rules.fs @@ -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 diff --git a/tests/CallPolly.Acceptance/Scenarios.fs b/tests/CallPolly.Acceptance/Scenarios.fs index c895ea8..c4db6a9 100644 --- a/tests/CallPolly.Acceptance/Scenarios.fs +++ b/tests/CallPolly.Acceptance/Scenarios.fs @@ -161,7 +161,7 @@ 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 [] ``CallLog - Can capture call-specific log entries isolated from overall log`` () = async { @@ -169,9 +169,9 @@ type Scenarios(output : Xunit.Abstractions.ITestOutputHelper) = 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 [] ``Trapping - Arbitrary Polly expressions can be used to define a failure condition`` () = async { @@ -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) @> } diff --git a/tests/CallPolly.Tests/RulesTests.fs b/tests/CallPolly.Tests/RulesTests.fs index 2de0810..5746003 100644 --- a/tests/CallPolly.Tests/RulesTests.fs +++ b/tests/CallPolly.Tests/RulesTests.fs @@ -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 [] ``dryRun mode does not inhibit processing`` () = async { @@ -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) @> let evnts = buffer.Take() @@ -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() @@ -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) @> let evnts = buffer.Take()