Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
da65739
implement Cause.Meta
adamgfraser Sep 19, 2019
0dec587
fix access levels
adamgfraser Sep 19, 2019
9a0abd0
make case class final
adamgfraser Sep 19, 2019
70edd5c
address review comments
adamgfraser Sep 19, 2019
2bcbbf5
migrate tests to ZIO Test
adamgfraser Sep 19, 2019
b8c1437
address review comments
adamgfraser Sep 22, 2019
af973a4
fix type
adamgfraser Sep 22, 2019
f2f5bc2
fix another typo
adamgfraser Sep 22, 2019
51712ec
pass `Data` in from above
adamgfraser Sep 23, 2019
9f2926d
implement flatMap
adamgfraser Sep 24, 2019
6c2e741
merge upstream changes
adamgfraser Sep 24, 2019
d17b505
implement flatten
adamgfraser Sep 24, 2019
cbdf7bb
implement unsandbox via flatten
adamgfraser Sep 24, 2019
1a76255
merge upstream changes
adamgfraser Oct 1, 2019
14ea0b4
apply nonFlaky only on JVM
adamgfraser Oct 1, 2019
5b5a2d0
use jvm test aspect more
adamgfraser Oct 1, 2019
3f39707
remove test
adamgfraser Oct 1, 2019
686a5df
try ignoring tests
adamgfraser Oct 1, 2019
d0468bb
start reenabling tests
adamgfraser Oct 1, 2019
3572eb4
remove unused import
adamgfraser Oct 1, 2019
51373fb
merge upstream changes
adamgfraser Oct 1, 2019
2e743b6
reenable more tests
adamgfraser Oct 1, 2019
d264395
Add ZSchedule.elapsed example to docs (#1871)
reibitto Oct 1, 2019
472bc18
ignore flaky supervision test (#1874)
adamgfraser Oct 1, 2019
ad007b2
CircleCI improvements (#1859)
sideeffffect Oct 1, 2019
0e13088
Implement ZIO#timeoutFork (#1856)
adamgfraser Oct 1, 2019
0f04654
revert change to ZStream#flatMap
adamgfraser Oct 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ load_cache: &load_cache
- restore_cache:
key: sbt-cache-v2

clean_cache: &clean_cache
- run:
name: Clean unwanted files from cache
command: |
rm -fv $HOME/.ivy2/.sbt.ivy.lock
find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete
find $HOME/.sbt -name "*.lock" -print -delete

save_cache: &save_cache
- save_cache:
key: sbt-cache-v2
Expand Down Expand Up @@ -92,6 +100,7 @@ compile: &compile
- run:
name: Compile code
command: ./sbt ++${SCALA_VERSION}! compileJVM
- <<: *clean_cache
- <<: *save_cache

lint: &lint
Expand All @@ -101,6 +110,7 @@ lint: &lint
- run:
name: Lint code
command: ./sbt ++${SCALA_VERSION}! check
- <<: *clean_cache
- <<: *save_cache

mdoc: &mdoc
Expand All @@ -112,6 +122,7 @@ mdoc: &mdoc
command: |
./sbt coreJVM/doc coreJS/doc streamsJVM/doc streamsJS/doc testJVM/doc testJS/doc
./sbt ++${SCALA_VERSION}! mdoc
- <<: *clean_cache
- <<: *save_cache

testJVM: &testJVM
Expand All @@ -122,7 +133,10 @@ testJVM: &testJVM
- run:
name: Run tests
command: ./sbt ++${SCALA_VERSION}! testJVM
- <<: *clean_cache
- <<: *save_cache
- store_test_results:
path: core-tests/jvm/target/test-reports

testJS: &testJS
steps:
Expand All @@ -133,7 +147,10 @@ testJS: &testJS
- run:
name: Run tests
command: ./sbt ++${SCALA_VERSION}! testJS
- <<: *clean_cache
- <<: *save_cache
- store_test_results:
path: core-tests/js/target/test-reports

release: &release
steps:
Expand Down Expand Up @@ -180,6 +197,7 @@ microsite: &microsite
node -v
./sbt docs/docusaurusCreateSite
./sbt docs/docusaurusPublishGhpages
- <<: *clean_cache
- <<: *save_cache

jobs:
Expand Down
30 changes: 0 additions & 30 deletions core-tests/shared/src/test/scala/zio/ArbitraryCause.scala

This file was deleted.

180 changes: 124 additions & 56 deletions core-tests/shared/src/test/scala/zio/CauseSpec.scala
Original file line number Diff line number Diff line change
@@ -1,59 +1,127 @@
package zio

import org.specs2.{ ScalaCheck, Specification }

class CauseSpec extends Specification with ScalaCheck {
import Cause._
import ArbitraryCause._

def is = "CauseSpec".title ^ s2"""
Cause
`Cause#died` and `Cause#stripFailures` are consistent $e1
`Cause.equals` is symmetric $e2
`Cause.equals` and `Cause.hashCode` satisfy the contract $e3
`Cause#untraced` removes all traces $e8
Then
`Then.equals` satisfies associativity $e4
`Then.equals` satisfies distributivity $e5
Both
`Both.equals` satisfies associativity $e6
`Both.equals` satisfies commutativity $e7
"""

private def e1 = prop { c: Cause[String] =>
if (c.died) c.stripFailures must beSome
else c.stripFailures must beNone
}

private def e2 = prop { (a: Cause[String], b: Cause[String]) =>
(a == b) must_== (b == a)
}

private def e3 =
prop { (a: Cause[String], b: Cause[String]) =>
(a == b) ==> (a.hashCode must_== (b.hashCode))
}.set(minTestsOk = 10, maxDiscardRatio = 99.0f)

private def e4 = prop { (a: Cause[String], b: Cause[String], c: Cause[String]) =>
Then(Then(a, b), c) must_== Then(a, Then(b, c))
Then(a, Then(b, c)) must_== Then(Then(a, b), c)
}

private def e5 = prop { (a: Cause[String], b: Cause[String], c: Cause[String]) =>
Then(a, Both(b, c)) must_== Both(Then(a, b), Then(a, c))
Then(Both(a, b), c) must_== Both(Then(a, c), Then(b, c))
}

private def e6 = prop { (a: Cause[String], b: Cause[String], c: Cause[String]) =>
Both(Both(a, b), c) must_== Both(a, Both(b, c))
Both(Both(a, b), c) must_== Both(a, Both(b, c))
}

private def e7 = prop { (a: Cause[String], b: Cause[String]) =>
Both(a, b) must_== Both(b, a)
}

private def e8 = prop { (c: Cause[String]) =>
c.untraced.traces.headOption must beNone
}
import zio.Cause.{ Both, Then }
import zio.random.Random
import zio.test._
import zio.test.Assertion._

import zio.CauseSpecUtil._

object CauseSpec
extends ZIOBaseSpec(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

suite("CauseSpec")(
suite("Cause")(
testM("`Cause#died` and `Cause#stripFailures` are consistent") {
check(causes) { c =>
assert(c.stripFailures, if (c.died) isSome(anything) else isNone)
}
},
testM("`Cause.equals` is symmetric") {
check(causes, causes) { (a, b) =>
assert(a == b, equalTo(b == a))
}
},
testM("`Cause.equals` and `Cause.hashCode` satisfy the contract") {
check(equalCauses) {
case (a, b) =>
assert(a.hashCode, equalTo(b.hashCode))
}
},
testM("`Cause#untraced` removes all traces") {
check(causes) { c =>
assert(c.untraced.traces.headOption, isNone)
}
}
),
suite("Then")(
testM("`Then.equals` satisfies associativity") {
check(causes, causes, causes) { (a, b, c) =>
assert(Then(Then(a, b), c), equalTo(Then(a, Then(b, c)))) &&
assert(Then(a, Then(b, c)), equalTo(Then(Then(a, b), c)))
}
},
testM("`Then.equals` satisfies distributivity") {
check(causes, causes, causes) { (a, b, c) =>
assert(Then(a, Both(b, c)), equalTo(Both(Then(a, b), Then(a, c)))) &&
assert(Then(Both(a, b), c), equalTo(Both(Then(a, c), Then(b, c))))
}
}
),
suite("Both")(
testM("`Both.equals` satisfies associativity") {
check(causes, causes, causes) { (a, b, c) =>
assert(Both(Both(a, b), c), equalTo(Both(a, Both(b, c)))) &&
assert(Both(a, Both(b, c)), equalTo(Both(Both(a, b), c)))
}
},
testM("`Both.equals` satisfies distributivity") {
check(causes, causes, causes) { (a, b, c) =>
assert(Both(Then(a, b), Then(a, c)), equalTo(Then(a, Both(b, c)))) &&
assert(Both(Then(a, c), Then(b, c)), equalTo(Then(Both(a, b), c)))
}
},
testM("`Both.equals` satisfies commutativity") {
check(causes, causes) { (a, b) =>
assert(Both(a, b), equalTo(Both(b, a)))
}
}
),
suite("Meta")(
testM("`Meta` is excluded from equals") {
check(causes) { c =>
assert(Cause.stackless(c), equalTo(c)) &&
assert(c, equalTo(Cause.stackless(c)))
}
},
testM("`Meta` is excluded from hashCode") {
check(causes) { c =>
assert(Cause.stackless(c).hashCode, equalTo(c.hashCode))
}
}
),
suite("Monad Laws:")(
testM("Left identity") {
check(causes) { c =>
assert(c.flatMap(Cause.fail), equalTo(c))
}
},
testM("Right identity") {
check(errors, errorCauseFunctions) { (e, f) =>
assert(Cause.fail(e).flatMap(f), equalTo(f(e)))
}
},
testM("Associativity") {
check(causes, errorCauseFunctions, errorCauseFunctions) { (c, f, g) =>
assert(c.flatMap(f).flatMap(g), equalTo(c.flatMap(e => f(e).flatMap(g))))
}
}
)
)
)

object CauseSpecUtil {

val causes: Gen[Random with Sized, Cause[String]] =
Gen.causes(Gen.anyString, Gen.anyString.map(s => new RuntimeException(s)))

val equalCauses: Gen[Random with Sized, (Cause[String], Cause[String])] =
(causes <*> causes <*> causes).flatMap {
case ((a, b), c) =>
Gen.elements(
(a, a),
(a, Cause.traced(a, ZTrace(0, Nil, Nil, None))),
(Then(Then(a, b), c), Then(a, Then(b, c))),
(Then(a, Both(b, c)), Both(Then(a, b), Then(a, c))),
(Both(Both(a, b), c), Both(a, Both(b, c))),
(Both(Then(a, c), Then(b, c)), Then(Both(a, b), c)),
(Both(a, b), Both(b, a)),
(a, Cause.stackless(a))
)
}

val errorCauseFunctions: Gen[Random with Sized, String => Cause[String]] =
Gen.function(causes)

val errors: Gen[Random with Sized, String] =
Gen.anyString
}
31 changes: 28 additions & 3 deletions core-tests/shared/src/test/scala/zio/ZIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import zio.ZIOSpecHelper._
import zio.clock.Clock
import zio.duration._
import zio.test._
import zio.test.mock.live
import zio.test.mock._
import zio.test.Assertion._
import zio.test.TestAspect.{ flaky, jvm, nonFlaky }
import zio.test.TestAspect.{ flaky, ignore, jvm, nonFlaky }

import scala.annotation.tailrec
import scala.util.{ Failure, Success }
Expand Down Expand Up @@ -641,7 +641,7 @@ object ZIOSpec
} yield ()).interruptChildren
r <- pa.await zip pb.await
} yield assert(r, equalTo((1, 2)))
} @@ flaky,
} @@ ignore,
testM("supervise fibers in race") {
for {
pa <- Promise.make[Nothing, Int]
Expand Down Expand Up @@ -1152,6 +1152,31 @@ object ZIOSpec

assertM(io, isTrue)
} @@ flaky
),
suite("timeoutFork")(
testM("returns `Right` with the produced value if the effect completes before the timeout elapses") {
assertM(ZIO.unit.timeoutFork(100.millis), isRight(isUnit))
},
testM("returns `Left` with the interrupting fiber otherwise") {
for {
fiber <- ZIO.never.uninterruptible.timeoutFork(100.millis).fork
_ <- MockClock.adjust(100.millis)
result <- fiber.join
} yield assert(result, isLeft(anything))
}
),
suite("unsandbox")(
testM("no information is lost during composition") {
val causes = Gen.causes(Gen.anyString, Gen.throwable)
def cause[R, E](zio: ZIO[R, E, Nothing]): ZIO[R, Nothing, Cause[E]] =
zio.foldCauseM(ZIO.succeed, ZIO.fail)
checkM(causes) { c =>
for {
result <- cause(ZIO.halt(c).sandbox.mapErrorCause(e => e.untraced).unsandbox)
} yield assert(result, equalTo(c)) &&
assert(result.prettyPrint, equalTo(c.prettyPrint))
}
}
)
)
)
Expand Down
6 changes: 3 additions & 3 deletions core-tests/shared/src/test/scala/zio/ZQueueSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import zio.clock.Clock
import zio.duration._
import zio.test._
import zio.test.Assertion._
import zio.test.TestAspect.nonFlaky
import zio.test.TestAspect.{ jvm, nonFlaky }
import zio.ZQueueSpecUtil.waitForSize

object ZQueueSpec
Expand Down Expand Up @@ -716,7 +716,7 @@ object ZQueueSpec
_ <- q.shutdown
_ <- f.await
} yield assert(true, isTrue)
} @@ nonFlaky(100),
} @@ jvm(nonFlaky(100)),
testM("shutdown race condition with take") {
for {
q <- Queue.bounded[Int](2)
Expand All @@ -726,7 +726,7 @@ object ZQueueSpec
_ <- q.shutdown
_ <- f.await
} yield assert(true, isTrue)
} @@ nonFlaky(100)
} @@ jvm(nonFlaky(100))
)
)

Expand Down
Loading