@@ -200,3 +200,44 @@ fn fifo_lifo_order() {
200
200
. collect ( ) ;
201
201
assert_eq ! ( vec, expected) ;
202
202
}
203
+
204
+ macro_rules! spawn_send {
205
+ ( $spawn: ident, $tx: ident, $i: expr) => { {
206
+ let tx = $tx. clone( ) ;
207
+ $spawn( move || tx. send( $i) . unwrap( ) ) ;
208
+ } } ;
209
+ }
210
+
211
+ /// Test mixed spawns pushing a series of numbers, interleaved such
212
+ /// such that negative values are using the second kind of spawn.
213
+ macro_rules! test_mixed_order {
214
+ ( $pos_spawn: ident, $neg_spawn: ident) => { {
215
+ let builder = ThreadPoolBuilder :: new( ) . num_threads( 1 ) ;
216
+ let pool = builder. build( ) . unwrap( ) ;
217
+ let ( tx, rx) = channel( ) ;
218
+ pool. install( move || {
219
+ spawn_send!( $pos_spawn, tx, 0 ) ;
220
+ spawn_send!( $neg_spawn, tx, -1 ) ;
221
+ spawn_send!( $pos_spawn, tx, 1 ) ;
222
+ spawn_send!( $neg_spawn, tx, -2 ) ;
223
+ spawn_send!( $pos_spawn, tx, 2 ) ;
224
+ spawn_send!( $neg_spawn, tx, -3 ) ;
225
+ spawn_send!( $pos_spawn, tx, 3 ) ;
226
+ } ) ;
227
+ rx. iter( ) . collect:: <Vec <i32 >>( )
228
+ } } ;
229
+ }
230
+
231
+ #[ test]
232
+ fn mixed_lifo_fifo_order ( ) {
233
+ let vec = test_mixed_order ! ( spawn, spawn_fifo) ;
234
+ let expected = vec ! [ 3 , -1 , 2 , -2 , 1 , -3 , 0 ] ;
235
+ assert_eq ! ( vec, expected) ;
236
+ }
237
+
238
+ #[ test]
239
+ fn mixed_fifo_lifo_order ( ) {
240
+ let vec = test_mixed_order ! ( spawn_fifo, spawn) ;
241
+ let expected = vec ! [ 0 , -3 , 1 , -2 , 2 , -1 , 3 ] ;
242
+ assert_eq ! ( vec, expected) ;
243
+ }
0 commit comments