* A helper to create a repeated fixture to test streaming writes against.
()
| 652 | * A helper to create a repeated fixture to test streaming writes against. |
| 653 | */ |
| 654 | async function createCall() { |
| 655 | const emitter = new EventTarget(); |
| 656 | |
| 657 | // If we write more than this number, the call will become unwritable. |
| 658 | const highwaterMark = 2; |
| 659 | let writeCounter = 0; |
| 660 | |
| 661 | // What has been "written" so far. |
| 662 | const written: any[] = []; |
| 663 | |
| 664 | const drain = () => { |
| 665 | writeCounter = 0; |
| 666 | emitter.dispatchEvent(new Event('drain')); |
| 667 | }; |
| 668 | |
| 669 | const cancel = () => { |
| 670 | emitter.dispatchEvent(new Event(CANCELLED_EVENT)); |
| 671 | }; |
| 672 | |
| 673 | const call = { |
| 674 | write: sinon.spy(value => { |
| 675 | // Simulating a writable stream becoming overwhelmed. |
| 676 | if (writeCounter++ < highwaterMark) { |
| 677 | // We can write this value to the stream. |
| 678 | written.push(value); |
| 679 | } |
| 680 | // But as soon as we pass the highwater mark, we can't write anymore. |
| 681 | return writeCounter < highwaterMark; |
| 682 | }), |
| 683 | end: sinon.spy(() => { |
| 684 | written.push('end'); |
| 685 | }), |
| 686 | emit: sinon.spy(), |
| 687 | request: sinon.spy(), |
| 688 | metadata: sinon.spy(), |
| 689 | sendMetadata: sinon.spy(), |
| 690 | on: (name, cb) => { |
| 691 | emitter.addEventListener(name, cb); |
| 692 | }, |
| 693 | off: (name, cb) => { |
| 694 | emitter.removeEventListener(name, cb); |
| 695 | }, |
| 696 | fire: { |
| 697 | drain, |
| 698 | cancel, |
| 699 | }, |
| 700 | }; |
| 701 | |
| 702 | const callback = sinon.spy(); |
| 703 | |
| 704 | const subject = new Subject<string>(); |
| 705 | const handlerResult = Promise.resolve(subject); |
| 706 | const methodHandler = () => handlerResult; |
| 707 | |
| 708 | const serviceMethod = server.createRequestStreamMethod( |
| 709 | methodHandler, |
| 710 | true, |
| 711 | ); |
no test coverage detected