Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package scalatest

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.

    Definition Classes
    org
  • package concurrent

    Classes, traits, and objects related to testing asynchronous and multi-threaded behavior.

    Classes, traits, and objects related to testing asynchronous and multi-threaded behavior.

    This package is released as part of the scalatest-core module.

    Definition Classes
    scalatest
  • trait Waiters extends PatienceConfiguration

    Trait that facilitates performing assertions outside the main test thread, such as assertions in callback methods that are invoked asynchronously.

    Trait that facilitates performing assertions outside the main test thread, such as assertions in callback methods that are invoked asynchronously.

    Trait Waiters provides a Waiter class that you can use to orchestrate the inter-thread communication required to perform assertions outside the main test thread, and a means to configure it.

    To use Waiter, create an instance of it in the main test thread:

    val w = new Waiter // Do this in the main test thread
    

    At some point later, call await on the waiter:

    w.await() // Call await() from the main test thread
    

    The await call will block until it either receives a report of a failed assertion from a different thread, at which point it will complete abruptly with the same exception, or until it is dismissed by a different thread (or threads), at which point it will return normally. You can optionally specify a timeout and/or a number of dismissals to wait for. Here's an example:

    import org.scalatest.time.SpanSugar._
    
    w.await(timeout(300 millis), dismissals(2))

    The default value for timeout, provided via an implicit PatienceConfig parameter, is 150 milliseconds. The default value for dismissals is 1. The await method will block until either it is dismissed a sufficient number of times by other threads or an assertion fails in another thread. Thus if you just want to perform assertions in just one other thread, only that thread will be performing a dismissal, so you can use the default value of 1 for dismissals.

    Waiter contains four overloaded forms of await, two of which take an implicit PatienceConfig parameter. To change the default timeout configuration, override or hide (if you imported the members of Waiters companion object instead of mixing in the trait) patienceConfig with a new one that returns your desired configuration.

    To dismiss a waiter, you just invoke dismiss on it:

    w.dismiss() // Call this from one or more other threads
    

    You may want to put dismiss invocations in a finally clause to ensure they happen even if an exception is thrown. Otherwise if a dismissal is missed because of a thrown exception, an await call will wait until it times out.

    Note that if a Waiter receives more than the expected number of dismissals, it will not report this as an error: i.e., receiving greater than the number of expected dismissals without any failed assertion will simply cause the the test to complete, not to fail. The only way a Waiter will cause a test to fail is if one of the asynchronous assertions to which it is applied fails.

    Finally, to perform an assertion in a different thread, you just apply the Waiter to the assertion code. Here are some examples:

    w { assert(1 + 1 === 3) }    // Can use assertions
    w { 1 + 1 should equal (3) } // Or matchers
    w { "hi".charAt(-1) }        // Any exceptions will be forwarded to await
    

    Here's a complete example:

    import org.scalatest._
    import concurrent.Waiters
    import scala.actors.Actor
    
    class ExampleSuite extends FunSuite with Matchers with Waiters {
    case class Message(text: String)
    class Publisher extends Actor {
    @volatile private var handle: Message => Unit = { (msg) => }
    def registerHandler(f: Message => Unit) { handle = f }
    def act() { var done = false while (!done) { react { case msg: Message => handle(msg) case "Exit" => done = true } } } }
    test("example one") {
    val publisher = new Publisher val message = new Message("hi") val w = new Waiter
    publisher.start()
    publisher.registerHandler { msg => w { msg should equal (message) } w.dismiss() }
    publisher ! message w.await() publisher ! "Exit" } }

    Definition Classes
    concurrent
  • Dismissals
  • PatienceConfig
  • Waiter

final case class Dismissals(value: Int) extends Product with Serializable

A configuration parameter that specifies the number of dismissals to wait for before returning normally from an await call on a Waiter.

value

the number of dismissals for which to wait

Source
Waiters.scala
Exceptions thrown

IllegalArgumentException if specified value is less than or equal to zero.

Linear Supertypes
Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Dismissals
  2. Serializable
  3. Product
  4. Equals
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Dismissals(value: Int)

    value

    the number of dismissals for which to wait

    Exceptions thrown

    IllegalArgumentException if specified value is less than or equal to zero.

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  8. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  9. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  10. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  12. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  13. def productElementNames: Iterator[String]
    Definition Classes
    Product
  14. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  15. val value: Int
  16. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  17. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  18. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped