Skip to content

Commit bab0bcf

Browse files
committed
more test for unbuffered test.
1 parent 67c88a7 commit bab0bcf

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

src/test/scala/gopher/channels/InputOpsSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ class InputOpsSuite extends FunSuite with AsyncAssertions {
275275
} }
276276
val a1 = ch1.awriteAll(1 to 10)
277277
val a2 = ch2.awriteAll((1 to 10)map(_*100))
278-
// it works, but in theory onComplete can be scheduled before. So, <= instead ==
278+
// it works, but for buffered channeld onComplete can be scheduled before. So, <= instead ==
279279
a1.onComplete{ case _ => { w{assert(sum <= 55)}; ch1.close(); w.dismiss() } }
280280
a2.onComplete{ case _ => { w{assert(sum <= 5555)}; w{assert(monotonic)}; w.dismiss() } }
281281
w.await(timeout(10 seconds), dismissals(2))

src/test/scala/gopher/channels/SelectSuite.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@ class SelectSuite extends FunSuite
118118
val selector = gopherApi.select.forever.idle{
119119
if (x >= 10) {
120120
gopherApi.currentFlow.exit(())
121-
}
122-
x=x+1
121+
} else {
122+
x=x+1
123+
}
123124
}.go
124125

125126

126127
Await.ready(selector, 10.second)
127128
assert(selector.isCompleted)
128-
assert(x==11)
129+
assert(x==10)
129130

130131
}
131132

src/test/scala/gopher/channels/UnbufferedSelectSuite.scala

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import gopher._
44
import gopher.channels._
55
import gopher.tags._
66

7-
import org.scalatest._
87

98
import scala.language._
109
import scala.concurrent._
1110
import scala.concurrent.duration._
1211

13-
class UnbufferedSelectSuite extends FunSuite
12+
import org.scalatest._
13+
import org.scalatest.concurrent._
14+
15+
class UnbufferedSelectSuite extends FunSuite with AsyncAssertions
1416
{
1517

1618
import scala.concurrent.ExecutionContext.Implicits.global
@@ -52,6 +54,31 @@ class UnbufferedSelectSuite extends FunSuite
5254
}
5355
}
5456

57+
test("append for finite unbuffered stream") {
58+
val w = new Waiter
59+
val ch1 = gopherApi.makeChannel[Int](0)
60+
val ch2 = gopherApi.makeChannel[Int](0)
61+
val appended = ch1 append ch2
62+
var sum = 0
63+
var prev = 0
64+
var monotonic = true
65+
val f = go { for(s <- appended) {
66+
// bug in compiler 2.11.7
67+
//w{assert(prev < s)}
68+
//if (prev >= s) w{assert(false)}
69+
if (prev >= s) monotonic=false
70+
prev = s
71+
sum += s
72+
} }
73+
val a1 = ch1.awriteAll(1 to 10)
74+
val a2 = ch2.awriteAll((1 to 10)map(_*100))
75+
// it works, but for buffered channeld onComplete can be scheduled before. So, <= instead ==
76+
a1.onComplete{ case _ => { w{assert(sum == 55)}; ch1.close(); w.dismiss() } }
77+
a2.onComplete{ case _ => { w{assert(sum == 5555)}; w{assert(monotonic)}; w.dismiss() } }
78+
w.await(timeout(10 seconds), dismissals(2))
79+
assert(sum==5555)
80+
assert(monotonic)
81+
}
5582

5683
lazy val gopherApi = CommonTestObjects.gopherApi
5784

0 commit comments

Comments
 (0)