Created
November 18, 2013 22:07
-
-
Save ubourdon/7536264 to your computer and use it in GitHub Desktop.
DurationTestTools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.concurrent.duration._ | |
trait DurationTestTools { | |
implicit def duration2DurationCompare(duration: Duration): DurationCompare = DurationCompare(duration) | |
case class DurationCompare(duration: Duration) { | |
def shouldBeMinusThan(expectedDuration: Duration) { assert(duration.compare(expectedDuration) < 0, s"$duration was not minus than $expectedDuration") } | |
def shouldBeMinusOrEqualThan(expectedDuration: Duration) { assert(duration.compare(expectedDuration) <= 0, s"$duration was not minus or equal than $expectedDuration") } | |
def shouldBeGreaterThan(expectedDuration: Duration) { assert(duration.compare(expectedDuration) > 0, s"$duration was not greater than $expectedDuration") } | |
def shouldBeGreaterOrEqualThan(expectedDuration: Duration) { assert(duration.compare(expectedDuration) >= 0, s"$duration was not greater or equal than $expectedDuration") } | |
def shouldBeEqualTo(expectedDuration: Duration) { assert(duration.compare(expectedDuration) == 0, s"$duration was not equal to $expectedDuration") } | |
} | |
def mesureTimeExecutionOf[T](toMesure: => T): (Duration, T) = { | |
val start = System.currentTimeMillis() | |
val result = toMesure | |
val stop = System.currentTimeMillis() | |
((stop - start) milliseconds, result) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalatest.{Matchers, BeforeAndAfterAll, FunSuite} | |
import scala.concurrent.duration._ | |
class ServerTest extends FunSuite with DurationTestTools { | |
test("ping server with 2 client") { | |
val (time, results) = mesureTimeExecutionOf { | |
(1 to 5).par.map { x => Source.fromURL("http://google.fr").mkString } | |
} | |
println(s"time elapsed for ${results.size} requests = $time") | |
time shouldBeMinusThan (500 milliseconds) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Connaissais pas. Je vais jeter un oeil.