@@ -4,110 +4,107 @@ import gopher._
4
4
import org .scalatest ._
5
5
import org .scalatest .concurrent ._
6
6
7
- import scala .concurrent .ExecutionContext .Implicits .global
8
7
import scala .concurrent ._
9
8
import scala .concurrent .duration ._
10
9
import scala .language ._
11
10
import scala .util ._
12
11
13
- class IOTimeoutsSuite extends FunSuite with Waiters {
12
+ class IOASyncTimeoutsSuite extends AsyncFunSuite {
14
13
15
-
16
- test(" messsaged from timeouts must be appear during reading attempt from empty channel" ) {
17
- val ch = gopherApi.makeChannel[String ]()
18
- val (chReady, chTimeout) = ch.withInputTimeouts(300 milliseconds)
19
- val w = new Waiter ()
20
- val f = gopherApi.select.once {
21
- case x : chReady.read => 1
22
- case x : chTimeout.read => 2
23
- }
24
- Await .ready(f map ( x => { w( assert(x == 2 ) ); w.dismiss() } ), 1 second )
25
- w.await()
26
- }
14
+ test(" messsaged from timeouts must be appear during reading attempt from empty channel" ) {
15
+ val ch = gopherApi.makeChannel[String ]()
16
+ val (chReady, chTimeout) = ch.withInputTimeouts(300 milliseconds)
17
+ val f = gopherApi.select.once {
18
+ case x : chReady.read => 1
19
+ case x : chTimeout.read => 2
20
+ }
21
+ for (x <- f) yield assert( x == 2 )
22
+ }
27
23
28
- test(" when we have value, we have no timeouts" ) {
29
- val ch = gopherApi.makeChannel[String ]()
30
- ch.awrite(" qqq" )
31
- val (chReady, chTimeout) = ch.withInputTimeouts(300 milliseconds)
32
- val w = new Waiter ()
33
- val f = gopherApi.select.once {
34
- case x : chReady.read => 1
35
- case x : chTimeout.read => 2
36
- }
37
- Await .ready(f map ( x => { w( assert(x == 1 ) ); w.dismiss() } ), 1 second )
38
- w.await()
39
- }
40
24
25
+ test(" when we have value, we have no timeouts" ) {
26
+ val ch = gopherApi.makeChannel[String ]()
27
+ ch.awrite(" qqq" )
28
+ val (chReady, chTimeout) = ch.withInputTimeouts(300 milliseconds)
29
+ val f = gopherApi.select.once {
30
+ case x : chReady.read => 1
31
+ case x : chTimeout.read => 2
32
+ }
33
+ for (x <- f) yield assert (x== 1 )
34
+ }
41
35
42
- test( " on input close it's timeout channel also must close " ) {
43
- val w = new Waiter ()
44
- val ch = gopherApi.makeChannel[String ](1 )
45
- Await .ready(ch.awrite( " qqq " ), 1 second)
46
- val (chReady, chTimeout) = ch.withInputTimeouts( 300 milliseconds )
47
- ch.close( )
48
- // now must read one element
49
- val f1 = gopherApi.select.once {
36
+
37
+ test( " on input close it's timeout channel also must close " ) {
38
+ val ch = gopherApi.makeChannel[String ](1 )
39
+ for {
40
+ _ <- ch.awrite( " qqq " )
41
+ (chReady, chTimeout) = ch.withInputTimeouts( 300 milliseconds )
42
+ _ = ch.close()
43
+ f1 = gopherApi.select.once {
50
44
case x : chReady.read => 1
51
45
case x : chTimeout.read => 2
52
- }
53
- Await .ready(f1 map ( x => { w( x == 1 ); w.dismiss() } ), 1 second )
54
- // now receive stream-closed exception
55
- val f2 = chReady.aread
56
- f2 onComplete { x => w(assert(x.isFailure && x.failed.get.isInstanceOf [ChannelClosedException ]))
57
- w.dismiss()
58
- }
59
- Await .ready(f2, 3 second)
60
- val f3 = chTimeout.aread
61
- f3 onComplete { x => w(assert(x.isFailure && x.failed.get.isInstanceOf [ChannelClosedException ]))
62
- w.dismiss()
63
- }
64
- Await .ready(f3, 6 seconds)
65
- w.await(dismissals= Dismissals (3 ))
66
-
67
- }
46
+ }
47
+ x <- f1
48
+ _ <- assert(x== 1 )
49
+ _ <- recoverToSucceededIf[ChannelClosedException ] {
50
+ chReady.aread
51
+ }
52
+ l <- recoverToSucceededIf[ChannelClosedException ] {
53
+ chTimeout.aread
54
+ }
55
+ } yield l
56
+ }
68
57
58
+ test(" messsaged from timeouts must be appear during attempt to write to filled unbuffered channel" ) {
59
+ val ch = gopherApi.makeChannel[Int ]()
60
+ val (chReady, chTimeout) = ch.withOutputTimeouts(150 milliseconds)
61
+ @ volatile var count = 1
62
+ val f = gopherApi.select.forever {
63
+ case x : chReady.write if (x== count) =>
64
+ {};
65
+ count += 1 // will newer called, since we have no reader
66
+ case t : chTimeout.read =>
67
+ implicitly[FlowTermination [Unit ]].doExit(count)
68
+ }
69
+ f map (_ => assert(count== 1 ))
70
+ }
69
71
70
- test(" messsaged from timeouts must be appear during attempt to write to filled unbuffered channel" ) {
71
- val ch = gopherApi.makeChannel[Int ]()
72
- val (chReady, chTimeout) = ch.withOutputTimeouts(150 milliseconds)
73
- @ volatile var count = 1
74
- val f = gopherApi.select.forever {
75
- case x : chReady.write if (x== count) =>
76
- {};
77
- count += 1 // will newer called, since we have no reader
78
- case t : chTimeout.read =>
79
- implicitly[FlowTermination [Unit ]].doExit(count)
80
- }
81
- Await .ready(f, 1 second)
82
- assert(count== 1 )
83
- }
72
+ test(" messsaged from timeouts must be appear during attempt to write to filled buffered channel" ) {
73
+ val ch = gopherApi.makeChannel[Int ](1 )
74
+ val (chReady, chTimeout) = ch.withOutputTimeouts(150 milliseconds)
75
+ @ volatile var count = 1
76
+ val f = gopherApi.select.forever {
77
+ case x : chReady.write if (x== count) =>
78
+ {};
79
+ count += 1
80
+ case t : chTimeout.read =>
81
+ implicitly[FlowTermination [Unit ]].doExit(count)
82
+ }
83
+ f map { _ => assert(count== 2 ) }
84
+ }
85
+
86
+ test(" when we have where to write -- no timeouts" ) {
87
+ val ch = gopherApi.makeChannel[Int ](1 )
88
+ val (chReady, chTimeout) = ch.withOutputTimeouts(300 milliseconds)
89
+ val f = gopherApi.select.once {
90
+ case x : chReady.write if (x== 1 ) => 1
91
+ case t : chTimeout.read => 2
92
+ }
93
+ f map { r => assert(r == 1 ) }
94
+ }
95
+
96
+
97
+
98
+ def gopherApi = CommonTestObjects .gopherApi
99
+
100
+
101
+ }
102
+
103
+ class IOSyncTimeoutsSuite extends FunSuite with Waiters {
104
+
105
+ import scala .concurrent .ExecutionContext .Implicits .global
84
106
85
- test(" messsaged from timeouts must be appear during attempt to write to filled buffered channel" ) {
86
- val ch = gopherApi.makeChannel[Int ](1 )
87
- val (chReady, chTimeout) = ch.withOutputTimeouts(150 milliseconds)
88
- @ volatile var count = 1
89
- val f = gopherApi.select.forever {
90
- case x : chReady.write if (x== count) =>
91
- {};
92
- count += 1
93
- case t : chTimeout.read =>
94
- implicitly[FlowTermination [Unit ]].doExit(count)
95
- }
96
- Await .ready(f, 3 second)
97
- assert(count== 2 )
98
- }
99
107
100
- test(" when we have where to write -- no timeouts" ) {
101
- val ch = gopherApi.makeChannel[Int ](1 )
102
- val (chReady, chTimeout) = ch.withOutputTimeouts(300 milliseconds)
103
- val f = gopherApi.select.once {
104
- case x : chReady.write if (x== 1 ) => 1
105
- case t : chTimeout.read => 2
106
- }
107
- val r = Await .result(f, 1 second)
108
- assert(r == 1 )
109
- }
110
-
111
108
test(" on output close it's timeout channel also must close" ) {
112
109
val ch = gopherApi.makeChannel[Int ](1 )
113
110
val (chReady, chTimeout) = ch.withOutputTimeouts(300 milliseconds)
0 commit comments