Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves performance of addition of contexts and addition of tests #217

Merged
merged 4 commits into from
Oct 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/canopy/runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ open reporters
open types
open OpenQA.Selenium

let rec private last = function
| hd :: [] -> hd
| hd :: tl -> last tl
| _ -> failwith "Empty list."
let private last = function
| hd :: tl -> hd
| [] -> failwith "Empty list."

let mutable suites = [new suite()]
let mutable todo = fun () -> ()
Expand All @@ -26,30 +25,30 @@ let context c =
else
let s = new suite()
s.Context <- c
suites <- suites @ [s]
suites <- s::suites
let private incrementLastTestSuite () =
let lastSuite = last suites
lastSuite.TotalTestsCount <- lastSuite.TotalTestsCount + 1
lastSuite
let ( &&& ) description f =
let lastSuite = incrementLastTestSuite()
lastSuite.Tests <- lastSuite.Tests @ [Test(description, f, lastSuite.TotalTestsCount)]
lastSuite.Tests <- Test(description, f, lastSuite.TotalTestsCount)::lastSuite.Tests
let test f = null &&& f
let ntest description f = description &&& f
let ( &&&& ) description f =
let lastSuite = incrementLastTestSuite()
lastSuite.Wips <- lastSuite.Wips @ [Test(description, f, lastSuite.TotalTestsCount)]
lastSuite.Wips <- Test(description, f, lastSuite.TotalTestsCount)::lastSuite.Wips
let wip f = null &&&& f
let many count f =
let lastSuite = incrementLastTestSuite()
[1 .. count] |> List.iter (fun _ -> lastSuite.Manys <- lastSuite.Manys @ [Test(null, f, lastSuite.TotalTestsCount)])
[1 .. count] |> List.iter (fun _ -> lastSuite.Manys <- Test(null, f, lastSuite.TotalTestsCount)::lastSuite.Manys)
let ( &&! ) description f =
let lastSuite = incrementLastTestSuite()
lastSuite.Tests <- lastSuite.Tests @ [Test(description, skipped, lastSuite.TotalTestsCount)]
lastSuite.Tests <- Test(description, skipped, lastSuite.TotalTestsCount)::lastSuite.Tests
let xtest f = null &&! f
let ( &&&&& ) description f =
let lastSuite = incrementLastTestSuite()
lastSuite.Always <- lastSuite.Always @ [Test(description, f, lastSuite.TotalTestsCount)]
lastSuite.Always <- Test(description, f, lastSuite.TotalTestsCount)::lastSuite.Always
let mutable passedCount = 0
let mutable skippedCount = 0
let mutable failedCount = 0
Expand Down Expand Up @@ -88,8 +87,12 @@ let failSuite (ex: Exception) (suite : suite) =
let reportFailedTest (ex: Exception) (test : Test) =
reporter.testStart test.Id
fail ex test.Id <| safelyGetUrl()
reporter.testEnd test.Id
suite.Tests |> List.iter (fun test -> reportFailedTest ex test)
reporter.testEnd test.Id

// tests are in reverse order and have to be reversed first
do suite.Tests
|> List.rev
|> List.iter (fun test -> reportFailedTest ex test)

let run () =
reporter.suiteBegin()
Expand Down Expand Up @@ -120,6 +123,9 @@ let run () =
reporter.testEnd test.Id

failureMessage <- null

// suites list is in reverse order and have to be reversed before running the tests
suites <- List.rev suites

//run all the suites
if runFailedContextsFirst = true then
Expand Down Expand Up @@ -149,13 +155,13 @@ let run () =
tests |> List.iter (fun w -> runtest s w)
wipTest <- false
else if s.Manys.IsEmpty = false then
s.Manys |> List.iter (fun m -> runtest s m)
s.Manys |> List.rev |> List.iter (fun m -> runtest s m)
else
let tests = s.Tests @ s.Always |> List.sortBy (fun t -> t.Number)
tests |> List.iter (fun t -> runtest s t)
s.Lastly ()

if contextFailed = true then failedContexts <- failedContexts @ [s.Context]
if contextFailed = true then failedContexts <- s.Context::failedContexts
if s.Context <> null then reporter.contextEnd s.Context
)

Expand All @@ -166,7 +172,8 @@ let run () =
reporter.suiteEnd()

let runFor browsers =
let currentSuites = suites
// suites are in reverse order and have to be reversed before running the tests
let currentSuites = suites |> List.rev
suites <- [new suite()]
match box browsers with
| :? (types.BrowserStartMode list) as browsers ->
Expand Down
15 changes: 14 additions & 1 deletion tests/basictests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,24 @@ context "todo tests"

"write a test that tests the whole internet!" &&& todo

let createTest k =
let testName = sprintf "Testing addition performance %i" k
testName &&& todo

let createTestSuite contextName n =
context contextName

[1..n] |> Seq.iter createTest

start chrome

createTestSuite "Add test performance" 1000

run ()

switchTo mainBrowser
coverage testpage
coverage()
coverage "http://scrumy.com/silenter39delayed"

quit()
quit()