final class TestContext extends ExecutionContext

A scala.concurrent.ExecutionContext implementation that can simulate async boundaries and time passage, useful for law testing purposes. This is intended primarily for datatype implementors. Most end-users will be better served by the cats.effect.testkit.TestControl utility, rather than using TestContext directly.

Usage for simulating an ExecutionContext):

implicit val ec = TestContext()

ec.execute(new Runnable { def run() = println("task1") })

ex.execute(new Runnable {
  def run() = {
    println("outer")

    ec.execute(new Runnable {
      def run() = println("inner")
    })
  }
})

// Nothing executes until `tick` gets called
ec.tick()

// Testing the resulting state
assert(ec.state.tasks.isEmpty)
assert(ec.state.lastReportedFailure == None)
Self Type
TestContext
Source
TestContext.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. TestContext
  2. ExecutionContext
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

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. def advance(time: FiniteDuration): Unit
  5. def advanceAndTick(time: FiniteDuration): Unit
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. def derive(): ExecutionContext
  9. def deriveBlocking(): ExecutionContext

    Derives a new ExecutionContext which delegates to this, but wrapping all tasks in scala.concurrent.blocking.

  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  12. def execute(runnable: Runnable): Unit
    Definition Classes
    TestContext → ExecutionContext
  13. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  14. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  16. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  17. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. def nextInterval(): FiniteDuration

    Returns the current interval between "now" and the earliest scheduled task.

    Returns the current interval between "now" and the earliest scheduled task. If there are tasks which will run immediately, this will return Duration.Zero. Passing this value to tick will guarantee minimum time-oriented progress on the task queue (e.g. tick(nextInterval())).

  19. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  20. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  21. def now(): FiniteDuration
  22. def reportFailure(cause: Throwable): Unit
    Definition Classes
    TestContext → ExecutionContext
  23. def schedule(delay: FiniteDuration, runnable: Runnable): () => Unit
  24. def seed: String
  25. def state: State

    Returns the internal state of the TestContext, useful for testing that certain execution conditions have been met.

  26. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  27. def tick(): Unit
    Annotations
    @tailrec()
  28. def tickAll(): Unit

    Repeatedly runs tick(nextInterval()) until all work has completed.

    Repeatedly runs tick(nextInterval()) until all work has completed. This is useful for emulating the quantized passage of time. For any discrete tick, the scheduler will randomly pick from all eligible tasks until the only remaining work is delayed. At that point, the scheduler will then advance the minimum delay (to the next time interval) and the process repeats.

    This is intuitively equivalent to "running to completion".

    Annotations
    @tailrec()
  29. def tickOne(): Boolean

    Executes just one tick, one task, from the internal queue, useful for testing that a some runnable will definitely be executed next.

    Executes just one tick, one task, from the internal queue, useful for testing that a some runnable will definitely be executed next.

    Returns a boolean indicating that tasks were available and that the head of the queue has been executed, so normally you have this equivalence:

    while (ec.tickOne()) {}
    // ... is equivalent with:
    ec.tick()

    Note that ask extraction has a random factor, the behavior being like tick, in order to simulate nondeterminism. So you can't rely on some ordering of execution if multiple tasks are waiting execution.

    returns

    true if a task was available in the internal queue, and was executed, or false otherwise

    Annotations
    @tailrec()
  30. def toString(): String
    Definition Classes
    AnyRef → Any
  31. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  32. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  33. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def prepare(): ExecutionContext
    Definition Classes
    ExecutionContext
    Annotations
    @deprecated
    Deprecated

    (Since version 2.12.0) preparation of ExecutionContexts will be removed

Inherited from ExecutionContext

Inherited from AnyRef

Inherited from Any

Ungrouped