Skip to content

Commit

Permalink
Increasing tolerance in WaitCompleted
Browse files Browse the repository at this point in the history
  • Loading branch information
ivelten committed Feb 1, 2019
1 parent c1cf5a4 commit fd65327
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
12 changes: 5 additions & 7 deletions tests/FSharp.Data.GraphQL.Tests/DeferredTests.fs
Expand Up @@ -7,8 +7,6 @@ open FSharp.Data.GraphQL
open FSharp.Data.GraphQL.Parser
open FSharp.Data.GraphQL.Execution
open System.Threading
open System.Collections.Generic
open System.Collections.Concurrent
open FSharp.Data.GraphQL.Types

#nowarn "40"
Expand Down Expand Up @@ -1320,7 +1318,7 @@ let ``Should buffer stream list correctly by timing information``() =
then fail "Timeout while waiting for first Deferred GQLResponse"
if TimeSpan.FromSeconds(float (ms 10)) |> mre2.WaitOne |> not
then fail "Timeout while waiting for second Deferred GQLResponse"
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received
|> Seq.cast<NameValueLookup>
|> itemEquals 0 expectedDeferred1
Expand Down Expand Up @@ -1386,7 +1384,7 @@ let ``Should buffer stream list correctly by count information``() =
then fail "Timeout while waiting for first Deferred GQLResponse"
if TimeSpan.FromSeconds(float (ms 10)) |> mre2.WaitOne |> not
then fail "Timeout while waiting for second Deferred GQLResponse"
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received
|> Seq.cast<NameValueLookup>
|> itemEquals 0 expectedDeferred1
Expand Down Expand Up @@ -1483,7 +1481,7 @@ let ``Each deferred result should be sent as soon as it is computed``() =
then fail "Timeout while waiting for first deferred result"
if TimeSpan.FromSeconds(float (ms 10)) |> mre2.WaitOne |> not
then fail "Timeout while waiting for second deferred result"
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received
|> Seq.cast<NameValueLookup>
|> itemEquals 0 expectedDeferred1
Expand Down Expand Up @@ -1540,7 +1538,7 @@ let ``Each deferred result of a list should be sent as soon as it is computed``
then fail "Timeout while waiting for first deferred result"
if TimeSpan.FromSeconds(float (ms 10)) |> mre2.WaitOne |> not
then fail "Timeout while waiting for second deferred result"
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received
|> Seq.cast<NameValueLookup>
|> itemEquals 0 expectedDeferred1
Expand Down Expand Up @@ -1598,7 +1596,7 @@ let ``Each streamed result should be sent as soon as it is computed - async seq`
then fail "Timeout while waiting for first deferred result"
if TimeSpan.FromSeconds(float (ms 10)) |> mre2.WaitOne |> not
then fail "Timeout while waiting for second deferred result"
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received
|> Seq.cast<NameValueLookup>
|> itemEquals 0 expectedDeferred1
Expand Down
15 changes: 9 additions & 6 deletions tests/FSharp.Data.GraphQL.Tests/Helpers.fs
Expand Up @@ -129,12 +129,15 @@ type TestObserver<'T>(obs : IObservable<'T>, ?onReceived : TestObserver<'T> -> '
do subscription <- obs.Subscribe(this)
member __.Received
with get() = received.AsEnumerable()
member __.WaitCompleted() =
wait mre "Timeout waiting for OnCompleted"
member x.WaitCompleted(expectedItemCount) =
x.WaitCompleted()
if received.Count < expectedItemCount
then failwithf "Expected to receive %i items, but received %i" expectedItemCount received.Count
member __.WaitCompleted(?expectedItemCount, ?timeout) =
let ms = defaultArg timeout 30
if TimeSpan.FromSeconds(float ms) |> mre.WaitOne |> not
then fail "Timeout waiting for OnCompleted"
match expectedItemCount with
| Some x ->
if received.Count < x
then failwithf "Expected to receive %i items, but received %i" x received.Count
| None -> ()
member __.WaitForItems(expectedItemCount) =
let errorMsg = sprintf "Expected to receive least %i items, but received %i" expectedItemCount received.Count
waitFor (fun () -> received.Count = expectedItemCount) (expectedItemCount * 100) errorMsg
Expand Down
36 changes: 18 additions & 18 deletions tests/FSharp.Data.GraphQL.Tests/ObservableExtensionsTests.fs
Expand Up @@ -25,23 +25,23 @@ let ``ofSeq should call OnComplete and return items in expected order`` () =
let source = seq { for x in 1 .. 5 do yield x }
let obs = Observable.ofSeq source
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals source

[<Fact>]
let `` bind should call OnComplete and return items in expected order`` () =
let source = seq { for x in 1 .. 5 do yield x }
let obs = Observable.ofSeq source |> Observable.bind (fun x -> Observable.ofSeq [x; x])
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ 1; 1; 2; 2; 3; 3; 4; 4; 5; 5 ]

[<Fact>]
let `` ofAsync should call OnComplete and return items in expected order`` () =
let source = async { return "test" }
let obs = Observable.ofAsync source
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ "test" ]


Expand All @@ -50,7 +50,7 @@ let `` ofAsyncVal should call OnComplete and return items in expected order`` ()
let source = async { return "test" } |> AsyncVal.ofAsync
let obs = Observable.ofAsyncVal source
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ "test" ]

[<Fact>]
Expand All @@ -65,7 +65,7 @@ let ``ofSeq on an empty sequence should call OnComplete and return items in expe
let source = Seq.empty<int>
let obs = Observable.ofSeq source
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals source

[<Fact>]
Expand All @@ -76,7 +76,7 @@ let ``ofAsyncSeq should call OnComplete and return items in expected order`` ()
yield delay 200 3 }
let obs = Observable.ofAsyncSeq source
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ 1; 3; 2 ]

[<Fact>]
Expand All @@ -87,7 +87,7 @@ let ``ofAsyncValSeq should call OnComplete and return items in expected order``
yield delay 200 3 |> AsyncVal.ofAsync }
let obs = Observable.ofAsyncValSeq source
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ 1; 3; 2 ]

[<Fact>]
Expand All @@ -98,7 +98,7 @@ let ``bufferByTiming should call OnComplete and return items in expected order``
yield delay 200 3 }
let obs = Observable.ofAsyncSeq source |> Observable.bufferByTiming (ms 300)
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ [1; 3]; [2] ]

[<Fact>]
Expand All @@ -109,7 +109,7 @@ let ``bufferByElementCount should call OnComplete and return items in expected o
yield delay 200 3 }
let obs = Observable.ofAsyncSeq source |> Observable.bufferByElementCount 2
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ [1; 3]; [2] ]

[<Fact>]
Expand All @@ -121,7 +121,7 @@ let ``bufferByTimingAndElementCount should call OnComplete and return items in e
yield delay 150 4 }
let obs = Observable.ofAsyncSeq source |> Observable.bufferByTimingAndElementCount (ms 300) 2
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ [1; 3]; [4]; [2] ]

type IndexException(index : int) =
Expand All @@ -135,7 +135,7 @@ let ``catch should call OnComplete and return items in expected order`` () =
Observable.ofSeq source
|> Observable.catch (fun (ex : IndexException) -> ex.Index |> Observable.singleton)
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ 1 ]

[<Fact>]
Expand All @@ -145,7 +145,7 @@ let ``choose should cal OnComplete`` () =
Observable.ofSeq source
|> Observable.choose (fun x -> match x % 2 with | 0 -> Some x | _ -> None)
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ 2; 4 ]

[<Fact>]
Expand All @@ -163,7 +163,7 @@ let ``concat should call OnComplete and return items in expected order`` () =
|> Observable.map Observable.ofAsyncSeq
|> Observable.concat
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ 1; 3; 2; 5; 4 ]

[<Fact>]
Expand All @@ -179,7 +179,7 @@ let ``concat2 should call OnComplete and return items in expected order`` () =
Observable.ofAsyncSeq source2
|> Observable.concat2 (Observable.ofAsyncSeq source1)
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ 1; 3; 2; 5; 4 ]

[<Fact>]
Expand All @@ -197,7 +197,7 @@ let ``merge should call OnComplete and return items in expected order`` () =
|> Observable.map Observable.ofAsyncSeq
|> Observable.merge
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ 1; 3; 5; 4; 2 ]

[<Fact>]
Expand All @@ -213,21 +213,21 @@ let ``merge2 should call OnComplete and return items in expected order`` () =
Observable.ofAsyncSeq source2
|> Observable.merge2 (Observable.ofAsyncSeq source1)
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals [ 1; 3; 5; 4; 2 ]

[<Fact>]
let ``concatSeq should call OnComplete and return items in expected order`` () =
let source = seq { for x in 1 .. 5 do yield x }
let obs = Observable.singleton source |> Observable.concatSeq
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals source

[<Fact>]
let ``mapAsync should call OnComplete and return items in expected order`` () =
let source = seq { for x in 1 .. 5 do yield x }
let obs = Observable.ofSeq source |> Observable.mapAsync (fun x -> async { return x })
use sub = Observer.create obs
sub.WaitCompleted()
sub.WaitCompleted(timeout = ms 10)
sub.Received |> seqEquals source

0 comments on commit fd65327

Please sign in to comment.