Permalink
Browse files

Refactored tests to avoid serialization failures upon test failure

  • Loading branch information...
mpilquist committed Jan 9, 2018
1 parent 8880b58 commit ed7db20c487ff2609bbcb0d440b7fa488cc5dd85
Showing with 62 additions and 20 deletions.
  1. +1 −0 core/js/src/test/scala/fs2/ScalaJsSanityTests.scala
  2. +1 −0 core/jvm/src/test/scala/fs2/CompressSpec.scala
  3. +2 −0 core/jvm/src/test/scala/fs2/ConcurrentlySpec.scala
  4. +2 −0 core/jvm/src/test/scala/fs2/MergeJoinSpec.scala
  5. +2 −0 core/jvm/src/test/scala/fs2/Pipe2Spec.scala
  6. +2 −1 core/jvm/src/test/scala/fs2/PipeSpec.scala
  7. +2 −0 core/jvm/src/test/scala/fs2/ResourceSafetySpec.scala
  8. +2 −0 core/jvm/src/test/scala/fs2/SchedulerSpec.scala
  9. +2 −0 core/jvm/src/test/scala/fs2/StreamAppSpec.scala
  10. +2 −0 core/jvm/src/test/scala/fs2/StreamPerformanceSpec.scala
  11. +2 −0 core/jvm/src/test/scala/fs2/StreamSpec.scala
  12. +1 −3 core/jvm/src/test/scala/fs2/TestUtilPlatform.scala
  13. +2 −0 core/jvm/src/test/scala/fs2/async/QueueSpec.scala
  14. +2 −0 core/jvm/src/test/scala/fs2/async/RaceSpec.scala
  15. +2 −0 core/jvm/src/test/scala/fs2/async/RefSpec.scala
  16. +2 −0 core/jvm/src/test/scala/fs2/async/SemaphoreSpec.scala
  17. +1 −0 core/jvm/src/test/scala/fs2/async/SignalSpec.scala
  18. +2 −0 core/jvm/src/test/scala/fs2/async/TopicSpec.scala
  19. +1 −1 core/shared/src/main/scala/fs2/Chunk.scala
  20. +2 −0 core/shared/src/test/scala/fs2/AwakeEverySpec.scala
  21. +2 −3 core/shared/src/test/scala/fs2/ChunkProps.scala
  22. +3 −2 core/shared/src/test/scala/fs2/ChunkSpec.scala
  23. +1 −0 core/shared/src/test/scala/fs2/ErrorHandlingSpec.scala
  24. +6 −2 core/shared/src/test/scala/fs2/Fs2Spec.scala
  25. +2 −0 core/shared/src/test/scala/fs2/RetrySpec.scala
  26. +1 −8 core/shared/src/test/scala/fs2/TestUtil.scala
  27. +2 −0 core/shared/src/test/scala/fs2/TextSpec.scala
  28. +2 −0 core/shared/src/test/scala/fs2/async/PromiseSpec.scala
  29. +1 −0 io/src/test/scala/fs2/io/IoSpec.scala
  30. +1 −0 io/src/test/scala/fs2/io/JavaInputOutputStreamSpec.scala
  31. +2 −0 io/src/test/scala/fs2/io/file/WatcherSpec.scala
  32. +2 −0 io/src/test/scala/fs2/io/tcp/SocketSpec.scala
  33. +2 −0 io/src/test/scala/fs2/io/udp/UdpSpec.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
@@ -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 {
@@ -4,6 +4,8 @@ import scala.concurrent.duration._
import cats.effect.IO
import fs2.async.Promise
import TestUtil._
class ConcurrentlySpec extends Fs2Spec {
"concurrently" - {
@@ -4,6 +4,8 @@ import scala.concurrent.duration._
import cats.effect.IO
import cats.implicits._
import TestUtil._
class MergeJoinSpec extends Fs2Spec {
"concurrent" - {
@@ -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
@@ -7,6 +7,7 @@ import cats.effect.IO
import cats.implicits._
import scala.concurrent.duration._
import TestUtil._
import fs2.Stream._
class PipeSpec extends Fs2Spec {
@@ -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) =>
@@ -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" - {
@@ -4,6 +4,8 @@ import cats.effect.IO
import cats.implicits._
import scala.concurrent.duration._
import TestUtil._
class SchedulerSpec extends AsyncFs2Spec {
"Scheduler" - {
@@ -7,6 +7,8 @@ import cats.implicits._
import fs2.StreamApp.ExitCode
import TestUtil._
class StreamAppSpec extends Fs2Spec {
"StreamApp" - {
@@ -3,6 +3,8 @@ package fs2
import java.util.concurrent.atomic.AtomicInteger
import cats.effect.IO
import TestUtil._
class StreamPerformanceSpec extends Fs2Spec {
"Stream Performance" - {
@@ -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" - {
@@ -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"))
@@ -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 {
@@ -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 =>
@@ -4,6 +4,8 @@ package async
import cats.effect.IO
import cats.implicits._
import TestUtil._
class RefSpec extends Fs2Spec with EventuallySupport {
"Ref" - {
@@ -6,6 +6,8 @@ import scala.concurrent.duration._
import cats.effect.IO
import cats.implicits._
import TestUtil._
class SemaphoreSpec extends Fs2Spec {
"Semaphore" - {
@@ -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" - {
@@ -5,6 +5,8 @@ import cats.effect.IO
import fs2._
import fs2.Stream._
import TestUtil._
import scala.concurrent.duration._
class TopicSpec extends Fs2Spec {
@@ -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
@@ -4,6 +4,8 @@ import scala.concurrent.duration._
import cats.effect.IO
import org.scalatest.Succeeded
import TestUtil._
class AwakeEverySpec extends AsyncFs2Spec {
"time" - {
@@ -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
@@ -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 {
@@ -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]]
@@ -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")
@@ -1,6 +1,7 @@
package fs2
import cats.effect._
import TestUtil._
class ErrorHandlingSpec extends Fs2Spec {
@@ -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 }
@@ -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)
@@ -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)
@@ -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
@@ -129,5 +124,3 @@ trait TestUtil extends TestUtilPlatform {
val nonEmptyNestedVectorGen: Gen[Vector[Vector[Int]]] = nestedVectorGen[Int](1,10)
}
object TestUtil extends TestUtil
@@ -3,6 +3,8 @@ package fs2
import org.scalacheck._
import fs2.text._
import TestUtil._
class TextSpec extends Fs2Spec {
"text" - {
"utf8Decoder" - {
@@ -7,6 +7,8 @@ import cats.implicits._
import scala.concurrent.duration._
import org.scalatest.EitherValues
import TestUtil._
class PromiseSpec extends AsyncFs2Spec with EitherValues {
"Promise" - {
@@ -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" - {
@@ -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 {
@@ -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" - {
@@ -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
@@ -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()

0 comments on commit ed7db20

Please sign in to comment.