Skip to content

Commit

Permalink
Refactored tests to avoid serialization failures upon test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilquist committed Jan 9, 2018
1 parent 8880b58 commit ed7db20
Show file tree
Hide file tree
Showing 33 changed files with 62 additions and 20 deletions.
1 change: 1 addition & 0 deletions core/js/src/test/scala/fs2/ScalaJsSanityTests.scala
@@ -1,6 +1,7 @@
package fs2

import cats.effect.IO
import TestUtil._

// ScalaTest doesn't currently support use of forAll with futures, which means
// tests that run streams from within forAll cannot be expressed. Until
Expand Down
1 change: 1 addition & 0 deletions core/jvm/src/test/scala/fs2/CompressSpec.scala
Expand Up @@ -8,6 +8,7 @@ import org.scalacheck.Gen
import java.io.ByteArrayOutputStream
import java.util.zip.{Deflater, DeflaterOutputStream, Inflater, InflaterOutputStream}

import TestUtil._
import compress._

class CompressSpec extends Fs2Spec {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/ConcurrentlySpec.scala
Expand Up @@ -4,6 +4,8 @@ import scala.concurrent.duration._
import cats.effect.IO
import fs2.async.Promise

import TestUtil._

class ConcurrentlySpec extends Fs2Spec {

"concurrently" - {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/MergeJoinSpec.scala
Expand Up @@ -4,6 +4,8 @@ import scala.concurrent.duration._
import cats.effect.IO
import cats.implicits._

import TestUtil._

class MergeJoinSpec extends Fs2Spec {

"concurrent" - {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/Pipe2Spec.scala
Expand Up @@ -5,6 +5,8 @@ import cats.effect.IO
import cats.implicits._
import org.scalacheck.Gen

import TestUtil._

class Pipe2Spec extends Fs2Spec {

// number of interrupt tests to run successive
Expand Down
3 changes: 2 additions & 1 deletion core/jvm/src/test/scala/fs2/PipeSpec.scala
Expand Up @@ -7,6 +7,7 @@ import cats.effect.IO
import cats.implicits._
import scala.concurrent.duration._

import TestUtil._
import fs2.Stream._

class PipeSpec extends Fs2Spec {
Expand Down Expand Up @@ -382,7 +383,7 @@ class PipeSpec extends Fs2Spec {
val s = Stream(1)
val f = (a: Int, b: Int) => a + b
val result = s.toVector.scan(0)(f)
runLog((s ++ never).scan(0)(f).take(result.size), timeout = 1 second) shouldBe result
runLog((s ++ never).scan(0)(f).take(result.size))(1 second) shouldBe result
}

"scan" in forAll { (s: PureStream[Int], n: Int) =>
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/ResourceSafetySpec.scala
Expand Up @@ -7,6 +7,8 @@ import org.scalacheck._
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import scala.concurrent.duration._

import TestUtil._

class ResourceSafetySpec extends Fs2Spec with EventuallySupport {

"Resource Safety" - {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/SchedulerSpec.scala
Expand Up @@ -4,6 +4,8 @@ import cats.effect.IO
import cats.implicits._
import scala.concurrent.duration._

import TestUtil._

class SchedulerSpec extends AsyncFs2Spec {

"Scheduler" - {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/StreamAppSpec.scala
Expand Up @@ -7,6 +7,8 @@ import cats.implicits._

import fs2.StreamApp.ExitCode

import TestUtil._

class StreamAppSpec extends Fs2Spec {

"StreamApp" - {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/StreamPerformanceSpec.scala
Expand Up @@ -3,6 +3,8 @@ package fs2
import java.util.concurrent.atomic.AtomicInteger
import cats.effect.IO

import TestUtil._

class StreamPerformanceSpec extends Fs2Spec {

"Stream Performance" - {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/StreamSpec.scala
Expand Up @@ -7,6 +7,8 @@ import org.scalacheck.Gen
import org.scalatest.Inside
import scala.concurrent.duration._

import TestUtil._

class StreamSpec extends Fs2Spec with Inside {

"Stream" - {
Expand Down
4 changes: 1 addition & 3 deletions core/jvm/src/test/scala/fs2/TestUtilPlatform.scala
Expand Up @@ -13,9 +13,7 @@ trait TestUtilPlatform {
ExecutionContext.Implicits.global
val mkScheduler: Stream[IO, Scheduler] = Scheduler[IO](1)

val timeout: FiniteDuration

def runLog[A](s: Stream[IO, A], timeout: FiniteDuration = timeout): Vector[A] =
def runLog[A](s: Stream[IO, A])(implicit timeout: FiniteDuration): Vector[A] =
s.compile.toVector
.unsafeRunTimed(timeout)
.getOrElse(throw new TimeoutException("IO run timed out"))
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/async/QueueSpec.scala
Expand Up @@ -5,6 +5,8 @@ import scala.concurrent.duration._
import cats.effect.IO
import cats.implicits._

import TestUtil._

class QueueSpec extends Fs2Spec {
"Queue" - {
"unbounded producer/consumer" in {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/async/RaceSpec.scala
Expand Up @@ -5,6 +5,8 @@ import cats.effect.IO
import scala.concurrent.duration._
import org.scalatest.EitherValues

import TestUtil._

class RaceSpec extends AsyncFs2Spec with EitherValues {
"Successful race" in {
val stream = mkScheduler.evalMap { s =>
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/async/RefSpec.scala
Expand Up @@ -4,6 +4,8 @@ package async
import cats.effect.IO
import cats.implicits._

import TestUtil._

class RefSpec extends Fs2Spec with EventuallySupport {

"Ref" - {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/async/SemaphoreSpec.scala
Expand Up @@ -6,6 +6,8 @@ import scala.concurrent.duration._
import cats.effect.IO
import cats.implicits._

import TestUtil._

class SemaphoreSpec extends Fs2Spec {

"Semaphore" - {
Expand Down
1 change: 1 addition & 0 deletions core/jvm/src/test/scala/fs2/async/SignalSpec.scala
Expand Up @@ -4,6 +4,7 @@ package async
import java.util.concurrent.atomic.AtomicLong
import cats.effect.IO
import cats.implicits._
import TestUtil._

class SignalSpec extends Fs2Spec {
"Signal" - {
Expand Down
2 changes: 2 additions & 0 deletions core/jvm/src/test/scala/fs2/async/TopicSpec.scala
Expand Up @@ -5,6 +5,8 @@ import cats.effect.IO
import fs2._
import fs2.Stream._

import TestUtil._

import scala.concurrent.duration._

class TopicSpec extends Fs2Spec {
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/fs2/Chunk.scala
Expand Up @@ -20,7 +20,7 @@ import cats.implicits._
* intermediate chunks being created (1 per call to `map`). In contrast, a chunk can be lifted to a segment
* (via `toSegment`) to get arbitrary operator fusion.
*/
abstract class Chunk[+O] {
abstract class Chunk[+O] extends Serializable {

/** Returns the number of elements in this chunk. */
def size: Int
Expand Down
2 changes: 2 additions & 0 deletions core/shared/src/test/scala/fs2/AwakeEverySpec.scala
Expand Up @@ -4,6 +4,8 @@ import scala.concurrent.duration._
import cats.effect.IO
import org.scalatest.Succeeded

import TestUtil._

class AwakeEverySpec extends AsyncFs2Spec {

"time" - {
Expand Down
5 changes: 2 additions & 3 deletions core/shared/src/test/scala/fs2/ChunkProps.scala
Expand Up @@ -5,12 +5,11 @@ import scala.reflect.ClassTag
import org.scalacheck.Arbitrary
import org.scalatest.Matchers
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import TestUtil._

object ChunkProps
extends Matchers
with GeneratorDrivenPropertyChecks
with TestUtil
{
with GeneratorDrivenPropertyChecks {
def propSize[A: Arbitrary, C <: Chunk[A]: Arbitrary] =
forAll { c: C =>
c.size shouldBe c.toVector.size
Expand Down
5 changes: 3 additions & 2 deletions core/shared/src/test/scala/fs2/ChunkSpec.scala
Expand Up @@ -9,6 +9,7 @@ import java.nio.ByteBuffer
import org.scalacheck.{ Arbitrary, Cogen, Gen }
import scala.reflect.ClassTag

import TestUtil._
import ChunkProps._

class ChunkSpec extends Fs2Spec {
Expand Down Expand Up @@ -105,7 +106,7 @@ class ChunkSpec extends Fs2Spec {
def testChunk[A: Arbitrary: ClassTag: Cogen: CommutativeMonoid: Eq](name: String, of: String, testTraverse: Boolean = true)(implicit C: Arbitrary[Chunk[A]]): Unit = {
s"$name" - {
"size" in propSize[A, Chunk[A]]
"take" in propTake[A, Chunk[A]]
"take" in propTake[A, Chunk[A]]
"drop" in propDrop[A, Chunk[A]]
"isempty" in propIsEmpty[A, Chunk[A]]
"toarray" in propToArray[A, Chunk[A]]
Expand All @@ -126,7 +127,7 @@ class ChunkSpec extends Fs2Spec {
def empty: Char = 0
}

testChunk[Byte]("Bytes", "Byte")
testChunk[Byte]("Bytes", "Byte")
testChunk[Short]("Shorts", "Short")
testChunk[Int]("Ints", "Int")
testChunk[Long]("Longs", "Long")
Expand Down
1 change: 1 addition & 0 deletions core/shared/src/test/scala/fs2/ErrorHandlingSpec.scala
@@ -1,6 +1,7 @@
package fs2

import cats.effect._
import TestUtil._

class ErrorHandlingSpec extends Fs2Spec {

Expand Down
8 changes: 6 additions & 2 deletions core/shared/src/test/scala/fs2/Fs2Spec.scala
@@ -1,6 +1,7 @@
package fs2

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

import org.typelevel.discipline.Laws
import org.scalatest.{ Args, AsyncFreeSpec, FreeSpec, Matchers, Status, Suite }
Expand All @@ -23,8 +24,11 @@ abstract class AsyncFs2Spec extends AsyncFreeSpec with Fs2SpecLike with AsyncTim

trait Fs2SpecLike extends Suite
with GeneratorDrivenPropertyChecks
with Matchers
with TestUtil {
with Matchers {

implicit val timeout: FiniteDuration = 60.seconds

lazy val verbose: Boolean = sys.props.get("fs2.test.verbose").isDefined

implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
PropertyCheckConfiguration(minSuccessful = 25, workers = 1)
Expand Down
2 changes: 2 additions & 0 deletions core/shared/src/test/scala/fs2/RetrySpec.scala
Expand Up @@ -3,6 +3,8 @@ package fs2
import scala.concurrent.duration._
import cats.effect.IO

import TestUtil._

class RetrySpec extends AsyncFs2Spec {
case class RetryErr(msg: String = "") extends RuntimeException(msg)

Expand Down
9 changes: 1 addition & 8 deletions core/shared/src/test/scala/fs2/TestUtil.scala
Expand Up @@ -4,17 +4,12 @@ import java.util.concurrent.TimeoutException
import org.scalacheck.{Arbitrary, Cogen, Gen, Shrink}

import scala.concurrent.Future
import scala.concurrent.duration._

import cats.effect.IO
import cats.implicits._
import fs2.internal.NonFatal

trait TestUtil extends TestUtilPlatform {

val timeout: FiniteDuration = 60.seconds

lazy val verbose: Boolean = sys.props.get("fs2.test.verbose").isDefined
object TestUtil extends TestUtilPlatform {

def runLogF[A](s: Stream[IO,A]): Future[Vector[A]] = (IO.shift *> s.compile.toVector).unsafeToFuture

Expand Down Expand Up @@ -129,5 +124,3 @@ trait TestUtil extends TestUtilPlatform {

val nonEmptyNestedVectorGen: Gen[Vector[Vector[Int]]] = nestedVectorGen[Int](1,10)
}

object TestUtil extends TestUtil
2 changes: 2 additions & 0 deletions core/shared/src/test/scala/fs2/TextSpec.scala
Expand Up @@ -3,6 +3,8 @@ package fs2
import org.scalacheck._
import fs2.text._

import TestUtil._

class TextSpec extends Fs2Spec {
"text" - {
"utf8Decoder" - {
Expand Down
2 changes: 2 additions & 0 deletions core/shared/src/test/scala/fs2/async/PromiseSpec.scala
Expand Up @@ -7,6 +7,8 @@ import cats.implicits._
import scala.concurrent.duration._
import org.scalatest.EitherValues

import TestUtil._

class PromiseSpec extends AsyncFs2Spec with EitherValues {

"Promise" - {
Expand Down
1 change: 1 addition & 0 deletions io/src/test/scala/fs2/io/IoSpec.scala
Expand Up @@ -3,6 +3,7 @@ package fs2.io
import java.io.{ByteArrayInputStream, InputStream}
import cats.effect.IO
import fs2.Fs2Spec
import fs2.TestUtil._

class IoSpec extends Fs2Spec {
"readInputStream" - {
Expand Down
1 change: 1 addition & 0 deletions io/src/test/scala/fs2/io/JavaInputOutputStreamSpec.scala
Expand Up @@ -2,6 +2,7 @@ package fs2.io

import cats.effect.IO
import fs2.{Chunk, Fs2Spec, Stream}
import fs2.TestUtil._
import org.scalacheck.{Arbitrary, Gen}

class JavaInputOutputStreamSpec extends Fs2Spec {
Expand Down
2 changes: 2 additions & 0 deletions io/src/test/scala/fs2/io/file/WatcherSpec.scala
Expand Up @@ -10,6 +10,8 @@ import java.io.IOException
import java.nio.file._
import java.nio.file.attribute.BasicFileAttributes

import TestUtil._

class WatcherSpec extends Fs2Spec {
"Watcher" - {
"supports watching a file" - {
Expand Down
2 changes: 2 additions & 0 deletions io/src/test/scala/fs2/io/tcp/SocketSpec.scala
Expand Up @@ -12,6 +12,8 @@ import fs2.internal.ThreadFactories

import org.scalatest.BeforeAndAfterAll

import TestUtil._

class SocketSpec extends Fs2Spec with BeforeAndAfterAll {

implicit val tcpACG: AsynchronousChannelGroup = AsynchronousChannelProvider
Expand Down
2 changes: 2 additions & 0 deletions io/src/test/scala/fs2/io/udp/UdpSpec.scala
Expand Up @@ -17,6 +17,8 @@ import cats.effect.IO
import cats.implicits._
import org.scalatest.BeforeAndAfterAll

import TestUtil._

class UdpSpec extends Fs2Spec with BeforeAndAfterAll {

implicit val AG = AsynchronousSocketGroup()
Expand Down

0 comments on commit ed7db20

Please sign in to comment.