trait ScaledTimeSpans extends AnyRef
Trait providing a scaled
method that can be used to scale time
Span
s used during the testing of asynchronous operations.
The scaled
method allows tests of asynchronous operations to be tuned
according to need. For example, Span
s can be scaled larger when running
tests on slower continuous integration servers or smaller when running on faster
development machines.
The Double
factor by which to scale the Span
s passed to
scaled
is obtained from the spanScaleFactor
method, also declared
in this trait. By default this method returns 1.0, but can be configured to return
a different value by passing a -F
argument to Runner
(or
an equivalent mechanism in an ant, sbt, or Maven build file).
The default timeouts and intervals defined for traits Eventually
and
Waiters
invoke scaled
, so those defaults
will be scaled automatically. Other than such defaults, however, to get a Span
to scale you'll need to explicitly pass it to scaled
.
For example, here's how you would scale a Span
you supply to
the failAfter
method from trait Timeouts
:
failAfter(scaled(150 millis)) { // ... }
The reason Span
s are not scaled automatically in the general case is
to make code obvious. If a reader sees failAfter(1 second)
, it will
mean exactly that: fail after one second. And if a Span
will be scaled,
the reader will clearly see that as well: failAfter(scaled(1 second))
.
Overriding spanScaleFactor
You can override the spanScaleFactor
method to configure the factor by a
different means. For example, to configure the factor from Akka
TestKit's test time factor you might create a trait like this:
import org.scalatest.concurrent.ScaledTimeSpans import akka.actor.ActorSystem import akka.testkit.TestKitExtension
trait AkkaSpanScaleFactor extends ScaledTimeSpans { override def spanScaleFactor: Double = TestKitExtension.get(ActorSystem()).TestTimeFactor }
This trait overrides spanScaleFactor
so that it takes its
scale factor from Akka's application.conf
file.
You could then scale Span
s tenfold in Akka's configuration file
like this:
akka { test { timefactor = 10.0 } }
Armed with this trait and configuration file, you can simply mix trait
AkkaSpanScaleFactor
into any test class whose Span
s
you want to scale, like this:
class MySpec extends FunSpec with Eventually with AkkaSpanScaleFactor { // .. }
- Source
- ScaledTimeSpans.scala
- Alphabetic
- By Inheritance
- ScaledTimeSpans
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def scaled(span: Span): Span
Scales the passed
Span
by theDouble
factor returned byspanScaleFactor
.Scales the passed
Span
by theDouble
factor returned byspanScaleFactor
.The
Span
is scaled by invoking itsscaledBy
method, thus this method has the same behavior: The value returned byspanScaleFactor
can be any positive number or zero, including a fractional number. A number greater than one will scale theSpan
up to a larger value. A fractional number will scale it down to a smaller value. A factor of 1.0 will cause the exact sameSpan
to be returned. A factor of zero will causeSpan.ZeroLength
to be returned. If overflow occurs,Span.Max
will be returned. If underflow occurs,Span.ZeroLength
will be returned.- Exceptions thrown
IllegalArgumentException
if the value returned fromspanScaleFactor
is less than zero
- def spanScaleFactor: Double
The factor by which the
scaled
method will scaleSpan
s.The factor by which the
scaled
method will scaleSpan
s.The default implementation of this method will return the span scale factor that was specified for the run, or 1.0 if no factor was specified. For example, you can specify a span scale factor when invoking ScalaTest via the command line by passing a
-F
argument toRunner
. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()