@@ -20,6 +20,7 @@ import { loginToIdC } from '../amazonq/utils/setup'
2020
2121describe ( 'Amazon Q Inline' , async function ( ) {
2222 let tempFolder : string
23+ const retries = 3
2324 const waitOptions = {
2425 interval : 500 ,
2526 timeout : 10000 ,
@@ -74,7 +75,7 @@ describe('Amazon Q Inline', async function () {
7475 waitOptions
7576 )
7677 if ( ! ok ) {
77- assert . fail (
78+ throw new Error (
7879 `Suggestions failed to become visible. Suggestion States: ${ JSON . stringify ( session . suggestionStates ) } `
7980 )
8081 }
@@ -117,7 +118,7 @@ describe('Amazon Q Inline', async function () {
117118 let originalEditorContents : string | undefined
118119
119120 describe ( 'supported filetypes' , ( ) => {
120- beforeEach ( async ( ) => {
121+ async function setup ( ) {
121122 await setupEditor ( )
122123
123124 /**
@@ -134,19 +135,42 @@ describe('Amazon Q Inline', async function () {
134135 * It seems like there are instances (race condition?) where amazon q starts generating when you open up
135136 * the file. Wait for that initial request to settle before doing anything
136137 */
137- await waitUntil ( async ( ) => {
138+ const ok = await waitUntil ( async ( ) => {
138139 console . table ( {
139140 'recommendation status' : RecommendationService . instance . isRunning ,
140141 'session id' : session . sessionId ,
141142 } )
142143 return ! RecommendationService . instance . isRunning && session . sessionId === ''
143144 } , waitOptions )
145+ if ( ! ok ) {
146+ throw new Error ( 'Recommendation service did not settle' )
147+ }
144148
145149 await invokeCompletion ( )
146150 originalEditorContents = vscode . window . activeTextEditor ?. document . getText ( )
147151
148152 // wait until the ghost text appears
149153 await waitForRecommendations ( )
154+ }
155+
156+ beforeEach ( async ( ) => {
157+ /**
158+ * Every once and a while the backend won't respond with any recommendations.
159+ * In those cases, re-try the setup up-to ${retries} times
160+ */
161+ let attempt = 0
162+ while ( attempt < retries ) {
163+ try {
164+ await setup ( )
165+ break
166+ } catch ( e ) {
167+ console . error ( e )
168+ attempt ++
169+ }
170+ }
171+ if ( attempt === retries ) {
172+ assert . fail ( `Failed to invoke ${ name } tests after ${ attempt } attempts` )
173+ }
150174 } )
151175
152176 it ( `${ name } invoke accept` , async function ( ) {
0 commit comments