org.scalatest.concurrent

ScaledTimeSpans

trait ScaledTimeSpans extends AnyRef

Trait providing a scaled method that can be used to scale time Spans used during the testing of asynchronous operations.

The scaled method allows tests of asynchronous operations to be tuned according to need. For example, Spans 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 Spans 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 for traits Eventually and AsyncAssertions 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 Spans 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.SpanScaleFactor
import akka.actor.ActorSystem
import akka.testkit.TestKitExtension

trait AkkaSpanScaleFactor extends SpanScaleFactor { 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 Spans 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 Spans you want to scale, like this:

class MySpec extends FunSpec with Eventually with AkkaSpanScaleFactor {
  // ..
}

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. ScaledTimeSpans
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All

Value Members

  1. def != (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  2. def != (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  3. def ## (): Int

    Attributes
    final
    Definition Classes
    AnyRef → Any
  4. def == (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  5. def == (arg0: Any): Boolean

    Attributes
    final
    Definition Classes
    Any
  6. def asInstanceOf [T0] : T0

    Attributes
    final
    Definition Classes
    Any
  7. def clone (): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  8. def eq (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  9. def equals (arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize (): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  11. def getClass (): java.lang.Class[_]

    Attributes
    final
    Definition Classes
    AnyRef
  12. def hashCode (): Int

    Definition Classes
    AnyRef → Any
  13. def isInstanceOf [T0] : Boolean

    Attributes
    final
    Definition Classes
    Any
  14. def ne (arg0: AnyRef): Boolean

    Attributes
    final
    Definition Classes
    AnyRef
  15. def notify (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  16. def notifyAll (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
  17. def scaled (span: Span): Span

    Scales the passed Span by the Double factor returned by spanScaleFactor.

    Scales the passed Span by the Double factor returned by spanScaleFactor.

    The Span is scaled by invoking its scaledBy method, thus this method has the same behavior: The value returned by spanScaleFactor can be any positive number or zero, including a fractional number. A number greater than one will scale the Span 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 same Span to be returned. A factor of zero will cause Span.ZeroLength to be returned. If overflow occurs, Span.Max will be returned. If underflow occurs, Span.ZeroLength will be returned.

    Attributes
    final
  18. def spanScaleFactor : Double

    The factor by which the scaled method will scale Spans. The default implementation of this method...

  19. def synchronized [T0] (arg0: ⇒ T0): T0

    Attributes
    final
    Definition Classes
    AnyRef
  20. def toString (): String

    Definition Classes
    AnyRef → Any
  21. def wait (): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  22. def wait (arg0: Long, arg1: Int): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()
  23. def wait (arg0: Long): Unit

    Attributes
    final
    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any