@@ -467,6 +467,7 @@ async function testWait(client: EchoClient) { |
467 | 467 | assert.deepStrictEqual(response.content, request.success.content); |
468 | 468 | } |
469 | 469 |
|
| 470 | +// a successful streaming call that has retry options passed but does not retry |
470 | 471 | async function testServerStreamingRetryOptions(client: SequenceServiceClient) { |
471 | 472 | const finalData: string[] = []; |
472 | 473 | const backoffSettings = createBackoffSettings( |
@@ -495,7 +496,7 @@ async function testServerStreamingRetryOptions(client: SequenceServiceClient) { |
495 | 496 | ); |
496 | 497 |
|
497 | 498 | const response = await client.createStreamingSequence(request); |
498 | | - await new Promise<void>(resolve => { |
| 499 | + await new Promise<void>((resolve, reject) => { |
499 | 500 | const sequence = response[0]; |
500 | 501 |
|
501 | 502 | const attemptRequest = |
@@ -509,8 +510,9 @@ async function testServerStreamingRetryOptions(client: SequenceServiceClient) { |
509 | 510 | attemptStream.on('data', (response: {content: string}) => { |
510 | 511 | finalData.push(response.content); |
511 | 512 | }); |
512 | | - attemptStream.on('error', () => { |
513 | | - //Do Nothing |
| 513 | + attemptStream.on('error', (error: GoogleError) => { |
| 514 | + // should not reach this |
| 515 | + reject(error); |
514 | 516 | }); |
515 | 517 | attemptStream.on('end', () => { |
516 | 518 | attemptStream.end(); |
@@ -524,6 +526,7 @@ async function testServerStreamingRetryOptions(client: SequenceServiceClient) { |
524 | 526 | }); |
525 | 527 | } |
526 | 528 |
|
| 529 | +// a streaming call that retries two times and finishes successfully |
527 | 530 | async function testServerStreamingRetrieswithRetryOptions( |
528 | 531 | client: SequenceServiceClient |
529 | 532 | ) { |
@@ -554,7 +557,7 @@ async function testServerStreamingRetrieswithRetryOptions( |
554 | 557 | ); |
555 | 558 |
|
556 | 559 | const response = await client.createStreamingSequence(request); |
557 | | - await new Promise<void>(resolve => { |
| 560 | + await new Promise<void>((resolve, reject) => { |
558 | 561 | const sequence = response[0]; |
559 | 562 |
|
560 | 563 | const attemptRequest = |
@@ -568,8 +571,8 @@ async function testServerStreamingRetrieswithRetryOptions( |
568 | 571 | attemptStream.on('data', (response: {content: string}) => { |
569 | 572 | finalData.push(response.content); |
570 | 573 | }); |
571 | | - attemptStream.on('error', () => { |
572 | | - //Do Nothing |
| 574 | + attemptStream.on('error', error => { |
| 575 | + reject(error); |
573 | 576 | }); |
574 | 577 | attemptStream.on('end', () => { |
575 | 578 | attemptStream.end(); |
@@ -583,6 +586,7 @@ async function testServerStreamingRetrieswithRetryOptions( |
583 | 586 | }); |
584 | 587 | } |
585 | 588 |
|
| 589 | +// a streaming call that retries twice using shouldRetryFn and finally succeeds |
586 | 590 | async function testServerStreamingRetriesWithShouldRetryFn( |
587 | 591 | client: SequenceServiceClient |
588 | 592 | ) { |
@@ -617,7 +621,7 @@ async function testServerStreamingRetriesWithShouldRetryFn( |
617 | 621 | ); |
618 | 622 |
|
619 | 623 | const response = await client.createStreamingSequence(request); |
620 | | - await new Promise<void>(resolve => { |
| 624 | + await new Promise<void>((resolve, reject) => { |
621 | 625 | const sequence = response[0]; |
622 | 626 | const attemptRequest = |
623 | 627 | new protos.google.showcase.v1beta1.AttemptStreamingSequenceRequest(); |
@@ -630,8 +634,9 @@ async function testServerStreamingRetriesWithShouldRetryFn( |
630 | 634 | attemptStream.on('data', (response: {content: string}) => { |
631 | 635 | finalData.push(response.content); |
632 | 636 | }); |
633 | | - attemptStream.on('error', () => { |
634 | | - // Do nothing |
| 637 | + attemptStream.on('error', error => { |
| 638 | + // should not reach this |
| 639 | + reject(error); |
635 | 640 | }); |
636 | 641 | attemptStream.on('end', () => { |
637 | 642 | attemptStream.end(); |
@@ -645,6 +650,7 @@ async function testServerStreamingRetriesWithShouldRetryFn( |
645 | 650 | }); |
646 | 651 | } |
647 | 652 |
|
| 653 | +// streaming call that retries twice using RetryRequestOptions instead of RetryOptions |
648 | 654 | async function testServerStreamingRetrieswithRetryRequestOptions( |
649 | 655 | client: SequenceServiceClient |
650 | 656 | ) { |
@@ -676,7 +682,7 @@ async function testServerStreamingRetrieswithRetryRequestOptions( |
676 | 682 | ); |
677 | 683 |
|
678 | 684 | const response = await client.createStreamingSequence(request); |
679 | | - await new Promise<void>(resolve => { |
| 685 | + await new Promise<void>((resolve, reject) => { |
680 | 686 | const sequence = response[0]; |
681 | 687 |
|
682 | 688 | const attemptRequest = |
@@ -690,8 +696,8 @@ async function testServerStreamingRetrieswithRetryRequestOptions( |
690 | 696 | attemptStream.on('data', (response: {content: string}) => { |
691 | 697 | finalData.push(response.content); |
692 | 698 | }); |
693 | | - attemptStream.on('error', () => { |
694 | | - // Do Nothing |
| 699 | + attemptStream.on('error', error => { |
| 700 | + reject(error); |
695 | 701 | }); |
696 | 702 | attemptStream.on('end', () => { |
697 | 703 | attemptStream.end(); |
@@ -704,6 +710,8 @@ async function testServerStreamingRetrieswithRetryRequestOptions( |
704 | 710 | ); |
705 | 711 | }); |
706 | 712 | } |
| 713 | + |
| 714 | +// streaming call that retries twice with RetryRequestOpsions and resumes from where it left off |
707 | 715 | async function testServerStreamingRetrieswithRetryRequestOptionsResumptionStrategy( |
708 | 716 | client: SequenceServiceClient |
709 | 717 | ) { |
@@ -748,7 +756,7 @@ async function testServerStreamingRetrieswithRetryRequestOptionsResumptionStrate |
748 | 756 | 'This is testing the brand new and shiny StreamingSequence server 3' |
749 | 757 | ); |
750 | 758 | const response = await client.createStreamingSequence(request); |
751 | | - await new Promise<void>(resolve => { |
| 759 | + await new Promise<void>((resolve, reject) => { |
752 | 760 | const sequence = response[0]; |
753 | 761 |
|
754 | 762 | const attemptRequest = |
@@ -762,8 +770,8 @@ async function testServerStreamingRetrieswithRetryRequestOptionsResumptionStrate |
762 | 770 | attemptStream.on('data', (response: {content: string}) => { |
763 | 771 | finalData.push(response.content); |
764 | 772 | }); |
765 | | - attemptStream.on('error', () => { |
766 | | - // do nothing |
| 773 | + attemptStream.on('error', error => { |
| 774 | + reject(error); |
767 | 775 | }); |
768 | 776 | attemptStream.on('end', () => { |
769 | 777 | attemptStream.end(); |
@@ -777,6 +785,7 @@ async function testServerStreamingRetrieswithRetryRequestOptionsResumptionStrate |
777 | 785 | }); |
778 | 786 | } |
779 | 787 |
|
| 788 | +// retries twice but fails with an error not from the streaming sequence |
780 | 789 | async function testServerStreamingRetrieswithRetryRequestOptionsErrorsOnBadResumptionStrategy( |
781 | 790 | client: SequenceServiceClient |
782 | 791 | ) { |
@@ -816,9 +825,8 @@ async function testServerStreamingRetrieswithRetryRequestOptionsErrorsOnBadResum |
816 | 825 | [1, 2, 11], |
817 | 826 | 'This is testing the brand new and shiny StreamingSequence server 3' |
818 | 827 | ); |
819 | | - const allowedCodes = [4, 14]; |
820 | 828 | const response = await client.createStreamingSequence(request); |
821 | | - await new Promise<void>((_, reject) => { |
| 829 | + await new Promise<void>(resolve => { |
822 | 830 | const sequence = response[0]; |
823 | 831 |
|
824 | 832 | const attemptRequest = |
@@ -831,21 +839,14 @@ async function testServerStreamingRetrieswithRetryRequestOptionsErrorsOnBadResum |
831 | 839 | ); |
832 | 840 |
|
833 | 841 | attemptStream.on('error', (e: GoogleError) => { |
834 | | - if (!allowedCodes.includes(e.code!)) { |
835 | | - reject(e); |
836 | | - } |
| 842 | + assert.strictEqual(e.code, 3); |
| 843 | + assert.match(e.note!, /not classified as transient/); |
| 844 | + resolve(); |
837 | 845 | }); |
838 | | - }).then( |
839 | | - () => { |
840 | | - assert(false); |
841 | | - }, |
842 | | - (err: GoogleError) => { |
843 | | - assert.strictEqual(err.code, 3); |
844 | | - assert.match(err.note!, /not classified as transient/); |
845 | | - } |
846 | | - ); |
| 846 | + }); |
847 | 847 | } |
848 | 848 |
|
| 849 | +// fails on the first error in the sequence |
849 | 850 | async function testServerStreamingThrowsClassifiedTransientErrorNote( |
850 | 851 | client: SequenceServiceClient |
851 | 852 | ) { |
@@ -875,7 +876,7 @@ async function testServerStreamingThrowsClassifiedTransientErrorNote( |
875 | 876 | ); |
876 | 877 |
|
877 | 878 | const response = await client.createStreamingSequence(request); |
878 | | - await new Promise<void>((_, reject) => { |
| 879 | + await new Promise<void>(resolve => { |
879 | 880 | const sequence = response[0]; |
880 | 881 |
|
881 | 882 | const attemptRequest = |
@@ -887,21 +888,14 @@ async function testServerStreamingThrowsClassifiedTransientErrorNote( |
887 | 888 | settings |
888 | 889 | ); |
889 | 890 | attemptStream.on('error', (e: GoogleError) => { |
890 | | - if (!allowedCodes.includes(e.code!)) { |
891 | | - reject(e); |
892 | | - } |
| 891 | + assert.strictEqual(e.code, 14); |
| 892 | + assert.match(e.note!, /not classified as transient/); |
| 893 | + resolve(); |
893 | 894 | }); |
894 | | - }).then( |
895 | | - () => { |
896 | | - assert(false); |
897 | | - }, |
898 | | - (err: GoogleError) => { |
899 | | - assert.strictEqual(err.code, 14); |
900 | | - assert.match(err.note!, /not classified as transient/); |
901 | | - } |
902 | | - ); |
| 895 | + }); |
903 | 896 | } |
904 | 897 |
|
| 898 | +// retries once and fails on the second error in the sequence |
905 | 899 | async function testServerStreamingRetriesAndThrowsClassifiedTransientErrorNote( |
906 | 900 | client: SequenceServiceClient |
907 | 901 | ) { |
@@ -931,7 +925,7 @@ async function testServerStreamingRetriesAndThrowsClassifiedTransientErrorNote( |
931 | 925 | ); |
932 | 926 |
|
933 | 927 | const response = await client.createStreamingSequence(request); |
934 | | - await new Promise<void>((_, reject) => { |
| 928 | + await new Promise<void>(resolve => { |
935 | 929 | const sequence = response[0]; |
936 | 930 |
|
937 | 931 | const attemptRequest = |
@@ -943,19 +937,11 @@ async function testServerStreamingRetriesAndThrowsClassifiedTransientErrorNote( |
943 | 937 | settings |
944 | 938 | ); |
945 | 939 | attemptStream.on('error', (e: GoogleError) => { |
946 | | - if (!allowedCodes.includes(e.code!)) { |
947 | | - reject(e); |
948 | | - } |
| 940 | + assert.strictEqual(e.code, 4); |
| 941 | + assert.match(e.note!, /not classified as transient/); |
| 942 | + resolve(); |
949 | 943 | }); |
950 | | - }).then( |
951 | | - () => { |
952 | | - assert(false); |
953 | | - }, |
954 | | - (err: GoogleError) => { |
955 | | - assert.strictEqual(err.code, 4); |
956 | | - assert.match(err.note!, /not classified as transient/); |
957 | | - } |
958 | | - ); |
| 944 | + }); |
959 | 945 | } |
960 | 946 |
|
961 | 947 | async function testServerStreamingThrowsCannotSetTotalTimeoutMillisMaxRetries( |
@@ -988,7 +974,7 @@ async function testServerStreamingThrowsCannotSetTotalTimeoutMillisMaxRetries( |
988 | 974 | ); |
989 | 975 |
|
990 | 976 | const response = await client.createStreamingSequence(request); |
991 | | - await new Promise<void>((_, reject) => { |
| 977 | + await new Promise<void>(resolve => { |
992 | 978 | const sequence = response[0]; |
993 | 979 |
|
994 | 980 | const attemptRequest = |
@@ -1000,22 +986,14 @@ async function testServerStreamingThrowsCannotSetTotalTimeoutMillisMaxRetries( |
1000 | 986 | settings |
1001 | 987 | ); |
1002 | 988 | attemptStream.on('error', (e: GoogleError) => { |
1003 | | - if (!allowedCodes.includes(e.code!)) { |
1004 | | - reject(e); |
1005 | | - } |
1006 | | - }); |
1007 | | - }).then( |
1008 | | - () => { |
1009 | | - assert(false); |
1010 | | - }, |
1011 | | - (err: GoogleError) => { |
1012 | | - assert.strictEqual(err.code, 3); |
| 989 | + assert.strictEqual(e.code, 3); |
1013 | 990 | assert.match( |
1014 | | - err.message, |
| 991 | + e.message, |
1015 | 992 | /Cannot set both totalTimeoutMillis and maxRetries/ |
1016 | 993 | ); |
1017 | | - } |
1018 | | - ); |
| 994 | + resolve(); |
| 995 | + }); |
| 996 | + }); |
1019 | 997 | } |
1020 | 998 |
|
1021 | 999 | async function main() { |
|