@@ -34,6 +34,7 @@ import { resolve } from 'path';
34
34
import { fileURLToPath } from 'url' ;
35
35
import * as bedrock from '@aws-sdk/client-bedrock-runtime' ;
36
36
import { e2eToolingClientConfig } from '../e2e_tooling_client_config.js' ;
37
+ import { runWithRetry } from '../retry.js' ;
37
38
38
39
// TODO: this is a work around
39
40
// it seems like as of amplify v6 , some of the code only runs in the browser ...
@@ -279,13 +280,14 @@ class ConversationHandlerTestProject extends TestProjectBase {
279
280
)
280
281
) ;
281
282
282
- await this . executeWithRetry ( ( ) =>
283
+ await this . executeWithRetry ( ( attempt ) =>
283
284
this . assertCustomConversationHandlerCanExecuteTurnWithParameterLessTool (
284
285
backendId ,
285
286
authenticatedUserCredentials . accessToken ,
286
287
dataUrl ,
287
288
apolloClient ,
288
- true
289
+ true ,
290
+ attempt
289
291
)
290
292
) ;
291
293
@@ -349,23 +351,25 @@ class ConversationHandlerTestProject extends TestProjectBase {
349
351
)
350
352
) ;
351
353
352
- await this . executeWithRetry ( ( ) =>
354
+ await this . executeWithRetry ( ( attempt ) =>
353
355
this . assertDefaultConversationHandlerCanPropagateError (
354
356
backendId ,
355
357
authenticatedUserCredentials . accessToken ,
356
358
dataUrl ,
357
359
apolloClient ,
358
- true
360
+ true ,
361
+ attempt
359
362
)
360
363
) ;
361
364
362
- await this . executeWithRetry ( ( ) =>
365
+ await this . executeWithRetry ( ( attempt ) =>
363
366
this . assertDefaultConversationHandlerCanPropagateError (
364
367
backendId ,
365
368
authenticatedUserCredentials . accessToken ,
366
369
dataUrl ,
367
370
apolloClient ,
368
- false
371
+ false ,
372
+ attempt
369
373
)
370
374
) ;
371
375
}
@@ -870,7 +874,8 @@ class ConversationHandlerTestProject extends TestProjectBase {
870
874
accessToken : string ,
871
875
graphqlApiEndpoint : string ,
872
876
apolloClient : ApolloClient < NormalizedCacheObject > ,
873
- streamResponse : boolean
877
+ streamResponse : boolean ,
878
+ attempt : number
874
879
) : Promise < void > => {
875
880
const customConversationHandlerFunction = (
876
881
await this . resourceFinder . findByBackendIdentifier (
@@ -880,13 +885,23 @@ class ConversationHandlerTestProject extends TestProjectBase {
880
885
)
881
886
) [ 0 ] ;
882
887
888
+ // Try different questions on retry.
889
+ // Retrying same question in narrow time frame usually yields same answer.
890
+ const questions = [
891
+ 'Give me a random number' ,
892
+ 'Give me a random number please' ,
893
+ 'Can you please give me a random number' ,
894
+ 'Generate and print random number' ,
895
+ ] ;
896
+ const question = questions [ attempt % questions . length ] ;
897
+
883
898
const message : CreateConversationMessageChatInput = {
884
899
conversationId : randomUUID ( ) . toString ( ) ,
885
900
id : randomUUID ( ) . toString ( ) ,
886
901
role : 'user' ,
887
902
content : [
888
903
{
889
- text : 'Give me a random number' ,
904
+ text : question ,
890
905
} ,
891
906
] ,
892
907
} ;
@@ -919,7 +934,8 @@ class ConversationHandlerTestProject extends TestProjectBase {
919
934
accessToken : string ,
920
935
graphqlApiEndpoint : string ,
921
936
apolloClient : ApolloClient < NormalizedCacheObject > ,
922
- streamResponse : boolean
937
+ streamResponse : boolean ,
938
+ attempt : number
923
939
) : Promise < void > => {
924
940
const defaultConversationHandlerFunction = (
925
941
await this . resourceFinder . findByBackendIdentifier (
@@ -929,13 +945,23 @@ class ConversationHandlerTestProject extends TestProjectBase {
929
945
)
930
946
) [ 0 ] ;
931
947
948
+ // Try different questions on retry.
949
+ // Retrying same question in narrow time frame usually yields same answer.
950
+ const questions = [
951
+ 'What is the value of PI?' ,
952
+ 'Give me the value of PI' ,
953
+ 'Give me the value of PI please' ,
954
+ 'Can you please give me the value of PI?' ,
955
+ ] ;
956
+ const question = questions [ attempt % questions . length ] ;
957
+
932
958
const message : CreateConversationMessageChatInput = {
933
959
id : randomUUID ( ) . toString ( ) ,
934
960
conversationId : randomUUID ( ) . toString ( ) ,
935
961
role : 'user' ,
936
962
content : [
937
963
{
938
- text : 'What is the value of PI?' ,
964
+ text : question ,
939
965
} ,
940
966
] ,
941
967
} ;
@@ -1031,20 +1057,8 @@ class ConversationHandlerTestProject extends TestProjectBase {
1031
1057
* Therefore, we wrap transactions in retry loop.
1032
1058
*/
1033
1059
private executeWithRetry = async (
1034
- callable : ( ) => Promise < void > ,
1035
- maxAttempts = 3
1060
+ callable : ( attempt : number ) => Promise < void >
1036
1061
) => {
1037
- const collectedErrors = [ ] ;
1038
- for ( let i = 1 ; i <= maxAttempts ; i ++ ) {
1039
- try {
1040
- await callable ( ) ;
1041
- // if successful return early;
1042
- return ;
1043
- } catch ( e ) {
1044
- collectedErrors . push ( e ) ;
1045
- }
1046
- }
1047
- // if we got here there were only errors
1048
- throw new AggregateError ( collectedErrors ) ;
1062
+ await runWithRetry ( callable , ( ) => true , 4 ) ;
1049
1063
} ;
1050
1064
}
0 commit comments