Skip to content

Instantly share code, notes, and snippets.

@adriansr
Created July 14, 2016 13:15
Show Gist options
  • Save adriansr/84ca838244f747784efd7bf426dfae56 to your computer and use it in GitHub Desktop.
Save adriansr/84ca838244f747784efd7bf426dfae56 to your computer and use it in GitHub Desktop.
/* stress test a JUnit test
given your test body:
feature(a) {
}
...
feature(c) {
}
wrap it:
feature("stress test") {
scenario("run") {
new StressTest {
def run() = {
body
}
}.run_all(num_repetitions,num_concurrent)
abstract class StressTest {
def run(): Unit
def feature(s:String)(body: =>Unit) = body
def scenario(s:String)(body: =>Unit) = body
def Given(s:String)=Unit
def Then(s:String)=Unit
def When(s:String)=Unit
def And(s:String)=Unit
def run_all(numLoops: Int, numConcurrent: Int) {
val f = Future.sequence(
(1 to numConcurrent).map(_=>Future {
for (num <- 1 to numLoops)
run()
})
)
Await.result(f,Duration.Inf)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment