|
92 | 92 | end |
93 | 93 |
|
94 | 94 | # Confirm all consumers are waiting: |
95 | | - expect(queue.waiting).to be == 3 |
| 95 | + expect(queue.waiting_count).to be == 3 |
96 | 96 |
|
97 | 97 | # Add items: |
98 | 98 | queue.push(:item1) |
|
134 | 134 | end |
135 | 135 |
|
136 | 136 | # Confirm all consumers are waiting: |
137 | | - expect(queue.waiting).to be == 4 |
| 137 | + expect(queue.waiting_count).to be == 4 |
138 | 138 |
|
139 | 139 | # Add items: |
140 | 140 | 4.times {|i| queue.push("item#{i}")} |
|
162 | 162 | results << [:high, queue.dequeue(priority: 10)] |
163 | 163 | end |
164 | 164 |
|
165 | | - expect(queue.waiting).to be == 2 |
| 165 | + expect(queue.waiting_count).to be == 2 |
166 | 166 |
|
167 | 167 | # Add one item - should go to high priority consumer: |
168 | 168 | queue.push(:item) |
|
198 | 198 | end |
199 | 199 |
|
200 | 200 | # Confirm low priority consumer is waiting: |
201 | | - expect(queue.waiting).to be == 1 |
| 201 | + expect(queue.waiting_count).to be == 1 |
202 | 202 |
|
203 | 203 | # Add an item - now we have waiters: |
204 | 204 | queue.push(:available_item) |
|
209 | 209 | end |
210 | 210 |
|
211 | 211 | # Confirm second low priority consumer is waiting (first one got the item): |
212 | | - expect(queue.waiting).to be == 1 |
| 212 | + expect(queue.waiting_count).to be == 1 |
213 | 213 |
|
214 | 214 | # Now a high priority consumer should jump ahead of remaining waiters: |
215 | 215 | high = reactor.async do |
216 | 216 | results << [:high, queue.dequeue(priority: 10)] |
217 | 217 | end |
218 | 218 |
|
219 | 219 | # Confirm high priority consumer is also waiting (total 2 waiting): |
220 | | - expect(queue.waiting).to be == 2 |
| 220 | + expect(queue.waiting_count).to be == 2 |
221 | 221 |
|
222 | 222 | # Add more items to satisfy all waiters: |
223 | 223 | queue.push(:item2) |
|
248 | 248 | end |
249 | 249 |
|
250 | 250 | # Confirm low priority waiter got item1 and finished: |
251 | | - expect(queue.waiting).to be == 0 |
| 251 | + expect(queue.waiting_count).to be == 0 |
252 | 252 |
|
253 | 253 | # The low priority waiter should have taken item1. |
254 | 254 | # High priority consumer gets item2: |
|
261 | 261 |
|
262 | 262 | with "#waiting" do |
263 | 263 | it "returns the number of waiting fibers" do |
264 | | - expect(queue.waiting).to be == 0 |
| 264 | + expect(queue.waiting_count).to be == 0 |
265 | 265 |
|
266 | 266 | task1 = reactor.async {queue.dequeue} |
267 | | - expect(queue.waiting).to be == 1 |
| 267 | + expect(queue.waiting_count).to be == 1 |
268 | 268 |
|
269 | 269 | task2 = reactor.async {queue.dequeue} |
270 | | - expect(queue.waiting).to be == 2 |
| 270 | + expect(queue.waiting_count).to be == 2 |
271 | 271 |
|
272 | 272 | queue.push(:item) |
273 | 273 | task1.wait |
274 | | - expect(queue.waiting).to be == 1 |
| 274 | + expect(queue.waiting_count).to be == 1 |
275 | 275 |
|
276 | 276 | queue.push(:item) |
277 | 277 | task2.wait |
278 | | - expect(queue.waiting).to be == 0 |
| 278 | + expect(queue.waiting_count).to be == 0 |
279 | 279 | end |
280 | 280 | end |
281 | 281 |
|
|
297 | 297 | end |
298 | 298 |
|
299 | 299 | # Confirm both async tasks are waiting: |
300 | | - expect(queue.waiting).to be == 2 |
| 300 | + expect(queue.waiting_count).to be == 2 |
301 | 301 |
|
302 | 302 | # Add items: |
303 | 303 | queue.push(:item1) |
|
330 | 330 | end |
331 | 331 |
|
332 | 332 | # Confirm all waiters are ready: |
333 | | - expect(queue.waiting).to be == 3 |
| 333 | + expect(queue.waiting_count).to be == 3 |
334 | 334 |
|
335 | 335 | # Add multiple items at once: |
336 | 336 | queue.enqueue(:item1, :item2, :item3) |
|
360 | 360 | end |
361 | 361 |
|
362 | 362 | # Confirm iterator is waiting: |
363 | | - expect(queue.waiting).to be == 1 |
| 363 | + expect(queue.waiting_count).to be == 1 |
364 | 364 |
|
365 | 365 | # Add items and nil to terminate: |
366 | 366 | queue.push(:first) |
|
394 | 394 | task = reactor.async {queue.dequeue(priority: 5)} |
395 | 395 |
|
396 | 396 | # Confirm waiter is ready: |
397 | | - expect(queue.waiting).to be == 1 |
| 397 | + expect(queue.waiting_count).to be == 1 |
398 | 398 |
|
399 | 399 | # Close the queue: |
400 | 400 | queue.close |
|
437 | 437 | end |
438 | 438 |
|
439 | 439 | # Confirm all consumers are waiting: |
440 | | - expect(queue.waiting).to be == num_consumers |
| 440 | + expect(queue.waiting_count).to be == num_consumers |
441 | 441 |
|
442 | 442 | # Add items: |
443 | 443 | num_items.times {|i| queue.push("item#{i}")} |
|
467 | 467 | task = reactor.async {queue.dequeue(priority: 5)} |
468 | 468 |
|
469 | 469 | # Confirm waiter is waiting: |
470 | | - expect(queue.waiting).to be == 1 |
| 470 | + expect(queue.waiting_count).to be == 1 |
471 | 471 |
|
472 | 472 | # Stop the waiting task: |
473 | 473 | task.stop |
|
485 | 485 | task = reactor.async {queue.dequeue(priority: 5)} |
486 | 486 |
|
487 | 487 | # Confirm waiter is waiting: |
488 | | - expect(queue.waiting).to be == 1 |
| 488 | + expect(queue.waiting_count).to be == 1 |
489 | 489 |
|
490 | 490 | # Stop the waiting task: |
491 | 491 | task.stop |
|
507 | 507 | task3 = reactor.async {results << [:task3, queue.dequeue(priority: 1)]} |
508 | 508 |
|
509 | 509 | # Confirm all three are waiting: |
510 | | - expect(queue.waiting).to be == 3 |
| 510 | + expect(queue.waiting_count).to be == 3 |
511 | 511 |
|
512 | 512 | # Stop first two tasks: |
513 | 513 | task1.stop |
|
522 | 522 | # BUG: Currently stopped waiters consume items: |
523 | 523 | expect(results).to be == [[:task3, :item1]] # Should get first item |
524 | 524 | expect(queue.size).to be == 1 # Second item should remain |
525 | | - expect(queue.waiting).to be == 0 # No waiters should remain |
| 525 | + expect(queue.waiting_count).to be == 0 # No waiters should remain |
526 | 526 | end |
527 | 527 |
|
528 | 528 | it "maintains correct priority order with stopped waiters" do |
|
534 | 534 | medium_task = reactor.async {results << [:medium, queue.dequeue(priority: 5)]} |
535 | 535 |
|
536 | 536 | # Confirm all are waiting: |
537 | | - expect(queue.waiting).to be == 3 |
| 537 | + expect(queue.waiting_count).to be == 3 |
538 | 538 |
|
539 | 539 | # Stop the high priority waiter (should have been first): |
540 | 540 | high_task.stop |
|
560 | 560 | queue.dequeue(priority: 1) |
561 | 561 | end |
562 | 562 |
|
563 | | - expect(queue.waiting).to be == 1 |
| 563 | + expect(queue.waiting_count).to be == 1 |
564 | 564 |
|
565 | 565 | # Stop the task (simulates exception) |
566 | 566 | task.stop |
|
592 | 592 | end |
593 | 593 |
|
594 | 594 | # Give tasks time to start waiting |
595 | | - expect(queue.waiting).to be == 3 |
| 595 | + expect(queue.waiting_count).to be == 3 |
596 | 596 |
|
597 | 597 | # Stop the middle priority task (priority 1) |
598 | 598 | tasks[1].stop |
|
0 commit comments