@@ -313,7 +313,11 @@ class SignalProducerLiftingSpec: QuickSpec {
313313 }
314314
315315 it ( " should interrupt ASAP and discard outstanding events " ) {
316- testAsyncASAPInterruption { $0. lazyMap ( on: $1) { $0 } }
316+ testAsyncASAPInterruption ( op: " lazyMap " ) { $0. lazyMap ( on: $1) { $0 } }
317+ }
318+
319+ it ( " should interrupt on the given scheduler " ) {
320+ testAsyncInterruptionScheduler ( op: " lazyMap " ) { $0. lazyMap ( on: $1) { $0 } }
317321 }
318322 }
319323
@@ -1133,7 +1137,11 @@ class SignalProducerLiftingSpec: QuickSpec {
11331137 }
11341138
11351139 it ( " should interrupt ASAP and discard outstanding events " ) {
1136- testAsyncASAPInterruption { $0. observe ( on: $1) }
1140+ testAsyncASAPInterruption ( op: " observe(on:) " ) { $0. observe ( on: $1) }
1141+ }
1142+
1143+ it ( " should interrupt on the given scheduler " ) {
1144+ testAsyncInterruptionScheduler ( op: " observe(on:) " ) { $0. observe ( on: $1) }
11371145 }
11381146 }
11391147
@@ -1200,7 +1208,11 @@ class SignalProducerLiftingSpec: QuickSpec {
12001208 }
12011209
12021210 it ( " should interrupt ASAP and discard outstanding events " ) {
1203- testAsyncASAPInterruption { $0. delay ( 10.0 , on: $1) }
1211+ testAsyncASAPInterruption ( op: " delay " ) { $0. delay ( 10.0 , on: $1) }
1212+ }
1213+
1214+ it ( " should interrupt on the given scheduler " ) {
1215+ testAsyncInterruptionScheduler ( op: " delay " ) { $0. delay ( 10.0 , on: $1) }
12041216 }
12051217 }
12061218
@@ -1298,13 +1310,21 @@ class SignalProducerLiftingSpec: QuickSpec {
12981310 }
12991311
13001312 it ( " should interrupt ASAP and discard outstanding events " ) {
1301- testAsyncASAPInterruption { $0. throttle ( 10.0 , on: $1) }
1313+ testAsyncASAPInterruption ( op: " throttle " ) { $0. throttle ( 10.0 , on: $1) }
1314+ }
1315+
1316+ it ( " should interrupt on the given scheduler " ) {
1317+ testAsyncInterruptionScheduler ( op: " throttle " ) { $0. throttle ( 10.0 , on: $1) }
13021318 }
13031319 }
13041320
13051321 describe ( " debounce " ) {
13061322 it ( " should interrupt ASAP and discard outstanding events " ) {
1307- testAsyncASAPInterruption { $0. delay ( 10.0 , on: $1) }
1323+ testAsyncASAPInterruption ( op: " debounce " ) { $0. debounce ( 10.0 , on: $1) }
1324+ }
1325+
1326+ it ( " should interrupt on the given scheduler " ) {
1327+ testAsyncInterruptionScheduler ( op: " debounce " ) { $0. debounce ( 10.0 , on: $1) }
13081328 }
13091329 }
13101330
@@ -2036,7 +2056,36 @@ class SignalProducerLiftingSpec: QuickSpec {
20362056 }
20372057}
20382058
2059+ private func testAsyncInterruptionScheduler(
2060+ op: String ,
2061+ file: FileString = #file,
2062+ line: UInt = #line,
2063+ transform: ( SignalProducer < Int , NoError > , TestScheduler ) -> SignalProducer < Int , NoError >
2064+ ) {
2065+ var isInterrupted = false
2066+
2067+ let scheduler = TestScheduler ( )
2068+ let producer = transform ( SignalProducer ( 0 ..< 128 ) , scheduler)
2069+
2070+ let failedExpectations = gatherFailingExpectations {
2071+ let disposable = producer. startWithInterrupted { isInterrupted = true }
2072+ expect ( isInterrupted) == false
2073+
2074+ disposable. dispose ( )
2075+ expect ( isInterrupted) == false
2076+
2077+ scheduler. run ( )
2078+ expect ( isInterrupted) == true
2079+ }
2080+
2081+ if !failedExpectations. isEmpty {
2082+ fail ( " The async operator ` \( op) ` does not interrupt on the appropriate scheduler. " ,
2083+ location: SourceLocation ( file: file, line: line) )
2084+ }
2085+ }
2086+
20392087private func testAsyncASAPInterruption(
2088+ op: String ,
20402089 file: FileString = #file,
20412090 line: UInt = #line,
20422091 transform: ( SignalProducer < Int , NoError > , TestScheduler ) -> SignalProducer < Int , NoError >
@@ -2073,7 +2122,7 @@ private func testAsyncASAPInterruption(
20732122 }
20742123
20752124 if !failedExpectations. isEmpty {
2076- fail ( " The ASAP interruption test of the async operator has failed. " ,
2125+ fail ( " The ASAP interruption test of the async operator ` \( op ) ` has failed." ,
20772126 location: SourceLocation ( file: file, line: line) )
20782127 }
20792128}
0 commit comments