Skip to content

Commit 7fe6994

Browse files
committed
Enable some tests on JS
1 parent 7332294 commit 7fe6994

File tree

1 file changed

+76
-79
lines changed

1 file changed

+76
-79
lines changed

core/shared/src/test/scala/fs2/StreamInterruptSuite.scala

Lines changed: 76 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -56,96 +56,93 @@ class StreamInterruptSuite extends Fs2Suite {
5656
}
5757
}
5858

59-
// These IO streams cannot be interrupted on JS b/c they never yield execution
60-
if (isJVM) {
61-
test("3 - constant stream") {
62-
val interruptSoon = Stream.sleep_[IO](20.millis).compile.drain.attempt
63-
Stream
64-
.constant(true)
65-
.interruptWhen(interruptSoon)
66-
.compile
67-
.drain
68-
.replicateA(interruptRepeatCount)
69-
}
59+
test("3 - constant stream") {
60+
val interruptSoon = Stream.sleep_[IO](20.millis).compile.drain.attempt
61+
Stream
62+
.constant(true)
63+
.interruptWhen(interruptSoon)
64+
.compile
65+
.drain
66+
.replicateA(interruptRepeatCount)
67+
}
7068

71-
test("4 - interruption of constant stream with a flatMap") {
72-
val interrupt =
73-
Stream.sleep_[IO](20.millis).compile.drain.attempt
74-
Stream
75-
.constant(true)
76-
.interruptWhen(interrupt)
77-
.flatMap(_ => Stream.emit(1))
78-
.compile
79-
.drain
80-
.replicateA(interruptRepeatCount)
81-
}
69+
test("4 - interruption of constant stream with a flatMap") {
70+
val interrupt =
71+
Stream.sleep_[IO](20.millis).compile.drain.attempt
72+
Stream
73+
.constant(true)
74+
.interruptWhen(interrupt)
75+
.flatMap(_ => Stream.emit(1))
76+
.compile
77+
.drain
78+
.replicateA(interruptRepeatCount)
79+
}
8280

83-
test("5 - interruption of an infinitely recursive stream") {
84-
val interrupt =
85-
Stream.sleep_[IO](20.millis).compile.drain.attempt
81+
test("5 - interruption of an infinitely recursive stream") {
82+
val interrupt =
83+
Stream.sleep_[IO](20.millis).compile.drain.attempt
8684

87-
def loop(i: Int): Stream[IO, Int] =
88-
Stream.emit(i).flatMap(i => Stream.emit(i) ++ loop(i + 1))
85+
def loop(i: Int): Stream[IO, Int] =
86+
Stream.emit(i).flatMap(i => Stream.emit(i) ++ loop(i + 1))
8987

90-
loop(0)
91-
.interruptWhen(interrupt)
92-
.compile
93-
.drain
94-
.replicateA(interruptRepeatCount)
95-
}
88+
loop(0)
89+
.interruptWhen(interrupt)
90+
.compile
91+
.drain
92+
.replicateA(interruptRepeatCount)
93+
}
9694

97-
test("6 - interruption of an infinitely recursive stream that never emits") {
98-
val interrupt =
99-
Stream.sleep_[IO](20.millis).compile.drain.attempt
95+
test("6 - interruption of an infinitely recursive stream that never emits") {
96+
val interrupt =
97+
Stream.sleep_[IO](20.millis).compile.drain.attempt
10098

101-
def loop: Stream[IO, Nothing] =
102-
Stream.eval(IO.unit) >> loop
99+
def loop: Stream[IO, Nothing] =
100+
Stream.eval(IO.unit) >> loop
103101

104-
loop
105-
.interruptWhen(interrupt)
106-
.compile
107-
.drain
108-
.replicateA(interruptRepeatCount)
109-
}
102+
loop
103+
.interruptWhen(interrupt)
104+
.compile
105+
.drain
106+
.replicateA(interruptRepeatCount)
107+
}
110108

111-
test("7 - interruption of an infinitely recursive stream that never emits and has no eval") {
112-
val interrupt = Stream.sleep_[IO](20.millis).compile.drain.attempt
113-
def loop: Stream[IO, Int] = Stream.emit(()) >> loop
114-
loop
115-
.interruptWhen(interrupt)
116-
.compile
117-
.drain
118-
.replicateA(interruptRepeatCount)
119-
}
109+
test("7 - interruption of an infinitely recursive stream that never emits and has no eval") {
110+
val interrupt = Stream.sleep_[IO](20.millis).compile.drain.attempt
111+
def loop: Stream[IO, Int] = Stream.emit(()) >> loop
112+
loop
113+
.interruptWhen(interrupt)
114+
.compile
115+
.drain
116+
.replicateA(interruptRepeatCount)
117+
}
120118

121-
test("8 - interruption of a stream that repeatedly evaluates") {
122-
val interrupt =
123-
Stream.sleep_[IO](20.millis).compile.drain.attempt
124-
Stream
125-
.repeatEval(IO.unit)
126-
.interruptWhen(interrupt)
127-
.compile
128-
.drain
129-
.replicateA(interruptRepeatCount)
130-
}
119+
test("8 - interruption of a stream that repeatedly evaluates") {
120+
val interrupt =
121+
Stream.sleep_[IO](20.millis).compile.drain.attempt
122+
Stream
123+
.repeatEval(IO.unit)
124+
.interruptWhen(interrupt)
125+
.compile
126+
.drain
127+
.replicateA(interruptRepeatCount)
128+
}
131129

132-
test("9 - interruption of the constant drained stream") {
133-
val interrupt =
134-
Stream.sleep_[IO](1.millis).compile.drain.attempt
135-
Stream
136-
.constant(true)
137-
.dropWhile(!_)
138-
.interruptWhen(interrupt)
139-
.compile
140-
.drain
141-
.replicateA(interruptRepeatCount)
142-
}
130+
test("9 - interruption of the constant drained stream") {
131+
val interrupt =
132+
Stream.sleep_[IO](1.millis).compile.drain.attempt
133+
Stream
134+
.constant(true)
135+
.dropWhile(!_)
136+
.interruptWhen(interrupt)
137+
.compile
138+
.drain
139+
.replicateA(interruptRepeatCount)
140+
}
143141

144-
test("10 - terminates when interruption stream is infinitely false") {
145-
forAllF { (s: Stream[Pure, Int]) =>
146-
val allFalse = Stream.constant(false)
147-
s.covary[IO].interruptWhen(allFalse).assertEmitsSameAs(s)
148-
}
142+
test("10 - terminates when interruption stream is infinitely false") {
143+
forAllF { (s: Stream[Pure, Int]) =>
144+
val allFalse = Stream.constant(false)
145+
s.covary[IO].interruptWhen(allFalse).assertEmitsSameAs(s)
149146
}
150147
}
151148

0 commit comments

Comments
 (0)