From ea10e9b94d8c0660eb2dcde9b0c81698203fc29d Mon Sep 17 00:00:00 2001 From: Adam Chlupacek Date: Sat, 22 Oct 2016 23:03:10 +0100 Subject: [PATCH 1/5] Fix set on Task Ref --- core/jvm/src/test/scala/fs2/TaskSpec.scala | 36 ++++++++++++++++++++++ core/shared/src/main/scala/fs2/Task.scala | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 core/jvm/src/test/scala/fs2/TaskSpec.scala diff --git a/core/jvm/src/test/scala/fs2/TaskSpec.scala b/core/jvm/src/test/scala/fs2/TaskSpec.scala new file mode 100644 index 0000000000..5a0b312277 --- /dev/null +++ b/core/jvm/src/test/scala/fs2/TaskSpec.scala @@ -0,0 +1,36 @@ +package fs2 + +/** + * Created by adamchlupacek on 22/10/16. + */ +class TaskSpec extends Fs2Spec{ + + + "Task" - { + + "Ref" - { + + "Set increments nonce" in { + + Task.ref[Int].flatMap{ref => + ref.setPure(1).flatMap{_ => + ref.access.flatMap{case ((_, set)) => + ref.setPure(2).flatMap{_ => + set(Right(3)) + } + + } + } + + }.unsafeRun() shouldBe false + + + } + + + } + + + } + +} diff --git a/core/shared/src/main/scala/fs2/Task.scala b/core/shared/src/main/scala/fs2/Task.scala index fd6b858e11..99d5c05de5 100644 --- a/core/shared/src/main/scala/fs2/Task.scala +++ b/core/shared/src/main/scala/fs2/Task.scala @@ -290,8 +290,8 @@ object Task extends TaskPlatform with TaskInstances { else { val r = result; val id = nonce; S { cb(r.map((_,id))) } } case Msg.Set(r) => + nonce += 1L if (result eq null) { - nonce += 1L val id = nonce waiting.values.foreach(cb => S { cb(r.map((_,id))) }) waiting = LinkedMap.empty From 845559b57adc9568c251f14d1e7d355102f56b6f Mon Sep 17 00:00:00 2001 From: Adam Chlupacek Date: Sat, 22 Oct 2016 23:18:42 +0100 Subject: [PATCH 2/5] Fix formating --- core/jvm/src/test/scala/fs2/TaskSpec.scala | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/core/jvm/src/test/scala/fs2/TaskSpec.scala b/core/jvm/src/test/scala/fs2/TaskSpec.scala index 5a0b312277..1680a63a16 100644 --- a/core/jvm/src/test/scala/fs2/TaskSpec.scala +++ b/core/jvm/src/test/scala/fs2/TaskSpec.scala @@ -5,11 +5,8 @@ package fs2 */ class TaskSpec extends Fs2Spec{ - "Task" - { - "Ref" - { - "Set increments nonce" in { Task.ref[Int].flatMap{ref => @@ -23,14 +20,7 @@ class TaskSpec extends Fs2Spec{ } }.unsafeRun() shouldBe false - - } - - } - - } - } From 3e20c19479c1baf98d27fedb0e4625697d3702db Mon Sep 17 00:00:00 2001 From: Adam Chlupacek Date: Sun, 23 Oct 2016 17:48:11 +0100 Subject: [PATCH 3/5] Remove pointless comment --- core/jvm/src/test/scala/fs2/TaskSpec.scala | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/jvm/src/test/scala/fs2/TaskSpec.scala b/core/jvm/src/test/scala/fs2/TaskSpec.scala index 1680a63a16..34ad25a1df 100644 --- a/core/jvm/src/test/scala/fs2/TaskSpec.scala +++ b/core/jvm/src/test/scala/fs2/TaskSpec.scala @@ -1,8 +1,5 @@ package fs2 -/** - * Created by adamchlupacek on 22/10/16. - */ class TaskSpec extends Fs2Spec{ "Task" - { @@ -15,10 +12,8 @@ class TaskSpec extends Fs2Spec{ ref.setPure(2).flatMap{_ => set(Right(3)) } - } } - }.unsafeRun() shouldBe false } } From ee775d4de4c281d555a938a489e43b2d763836bf Mon Sep 17 00:00:00 2001 From: Adam Chlupacek Date: Sun, 23 Oct 2016 21:37:15 +0100 Subject: [PATCH 4/5] Fix for race on set in test --- core/jvm/src/test/scala/fs2/TaskSpec.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/jvm/src/test/scala/fs2/TaskSpec.scala b/core/jvm/src/test/scala/fs2/TaskSpec.scala index 34ad25a1df..13cec5b2a4 100644 --- a/core/jvm/src/test/scala/fs2/TaskSpec.scala +++ b/core/jvm/src/test/scala/fs2/TaskSpec.scala @@ -1,5 +1,7 @@ package fs2 +import scala.concurrent.duration._ + class TaskSpec extends Fs2Spec{ "Task" - { @@ -10,7 +12,7 @@ class TaskSpec extends Fs2Spec{ ref.setPure(1).flatMap{_ => ref.access.flatMap{case ((_, set)) => ref.setPure(2).flatMap{_ => - set(Right(3)) + set(Right(3)).schedule(100.millis) } } } From 8baa5ce7cff4147ad5da14b32772f84e7da468e9 Mon Sep 17 00:00:00 2001 From: Adam Chlupacek Date: Wed, 26 Oct 2016 02:23:33 +0100 Subject: [PATCH 5/5] Change test's description --- core/jvm/src/test/scala/fs2/TaskSpec.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/jvm/src/test/scala/fs2/TaskSpec.scala b/core/jvm/src/test/scala/fs2/TaskSpec.scala index 13cec5b2a4..89a6792a18 100644 --- a/core/jvm/src/test/scala/fs2/TaskSpec.scala +++ b/core/jvm/src/test/scala/fs2/TaskSpec.scala @@ -6,7 +6,12 @@ class TaskSpec extends Fs2Spec{ "Task" - { "Ref" - { - "Set increments nonce" in { + + /** + * Tests whether set after access causes said access's + * set to default to no-op as the value in ref has changed + */ + "Interleaving set and access " in { Task.ref[Int].flatMap{ref => ref.setPure(1).flatMap{_ =>