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

Commit

Permalink
More elegant test hack
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Oct 14, 2018
1 parent 3b244ce commit 87b07ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 6 additions & 9 deletions tests/CallPolly.Acceptance/Scenarios.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ module Helpers =
let s x = TimeSpan.FromSeconds (float x)
let between min max (value : float) = value >= min && value <= max

type SerilogHelpers.LogCaptureBuffer with
member buffer.Take() =
let actual = [for x in buffer.Entries -> x.RenderMessage()]
buffer.Clear()
actual

let policy = """{
"services": {
"ingres": {
Expand Down Expand Up @@ -262,9 +256,12 @@ type Scenarios(output : Xunit.Abstractions.ITestOutputHelper) =
test <@ between 0.3 2. (let t = time.Elapsed in t.TotalSeconds) @>
}

let readDefinitions () = policy
// Uncomment to read from, or debug using a custom policy
//let readDefinitions () = System.Environment.GetEnvironmentVariable "CALL_POLICY" |> System.IO.File.ReadAllText
let readDefinitions () =
let filename = System.Environment.GetEnvironmentVariable "CALL_POLICY"
// Uncomment as a test hack!
//let filename = "c:\code\CALL_POLICIES"
if filename <> null && System.IO.File.Exists filename then System.IO.File.ReadAllText filename
else policy

let renderAsPrettyJson x = Parser.Newtonsoft.Serialize(x, Parser.Newtonsoft.indentSettings)

Expand Down
9 changes: 7 additions & 2 deletions tests/CallPolly.Tests/Infrastructure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module Choice =
module SerilogHelpers =
open Serilog
open Serilog.Events
open System.Collections.Concurrent

/// Create a logger, targeting the specified outputs
[<NoComparison>]
Expand All @@ -96,12 +97,16 @@ module SerilogHelpers =
interface Serilog.Core.ILogEventSink with member __.Emit logEvent = writeSerilogEvent logEvent

type LogCaptureBuffer() =
let captured = ResizeArray()
let captured = ConcurrentQueue()
let capture (logEvent: LogEvent) =
captured.Add logEvent
captured.Enqueue logEvent
interface Serilog.Core.ILogEventSink with member __.Emit logEvent = capture logEvent
member __.Clear () = captured.Clear()
member __.Entries = captured.ToArray()
member __.Take() =
let actual = [for x in __.Entries -> x.RenderMessage()]
__.Clear()
actual

let (|SerilogScalar|_|) : Serilog.Events.LogEventPropertyValue -> obj option = function
| (:? ScalarValue as x) -> Some x.Value
Expand Down

0 comments on commit 87b07ba

Please sign in to comment.