@@ -82,23 +82,34 @@ export async function waitForTreeItems(
8282 }
8383}
8484
85- export async function waitForPythonExtension ( ) {
85+ export async function waitForPythonExtension ( timeoutMs : number ) {
8686 const section = await getViewSection ( "CONFIGURATION" ) ;
8787 assert ( section ) ;
88- const welcome = await section . findWelcomeContent ( ) ;
89- assert ( welcome ) ;
90- sleep ( 1000 ) ;
9188 const workbench = await browser . getWorkbench ( ) ;
92- const notifs = await workbench . getNotifications ( ) ;
93- for ( const n of notifs ) {
94- if (
95- ( await n . getActions ( ) ) . find (
96- ( btn ) => btn . getTitle ( ) === "Install and Reload"
97- ) !== undefined
98- ) {
99- await n . takeAction ( "Install and Reload" ) ;
89+
90+ await browser . waitUntil (
91+ async ( ) => {
92+ const notifs = await workbench . getNotifications ( ) ;
93+ let found = false ;
94+ for ( const n of notifs ) {
95+ if (
96+ ( await n . getActions ( ) ) . find (
97+ ( btn ) => btn . getTitle ( ) === "Install and Reload"
98+ ) !== undefined
99+ ) {
100+ await n . takeAction ( "Install and Reload" ) ;
101+ found = true ;
102+ }
103+ }
104+ return found ;
105+ } ,
106+ {
107+ timeout : 5 * 1000 ,
108+ interval : 500 ,
109+ timeoutMsg :
110+ "Can't find notification to install ms-python extension" ,
100111 }
101- }
112+ ) ;
102113
103114 await browser . waitUntil (
104115 async ( ) =>
@@ -108,16 +119,115 @@ export async function waitForPythonExtension() {
108119 ) ?. getTitle ( )
109120 ) ?. includes ( "README.quickstart.md" ) === true ,
110121 {
111- timeout : 120000 ,
122+ timeout : timeoutMs ,
112123 timeoutMsg :
113124 "Timeout when installing python extension and reloading" ,
114125 }
115126 ) ;
116127
117- sleep ( 500 ) ;
128+ await sleep ( 500 ) ;
118129 try {
130+ const notifs = await workbench . getNotifications ( ) ;
119131 for ( const n of notifs ) {
120132 await n . dismiss ( ) ;
121133 }
122134 } catch { }
123135}
136+
137+ export async function waitForPythonExtensionWithRetry (
138+ timeoutMs : number ,
139+ retryCount : number
140+ ) {
141+ for ( let i = 0 ; i < retryCount ; i ++ ) {
142+ try {
143+ const section = await getViewSection ( "CONFIGURATION" ) ;
144+ assert ( section ) ;
145+ await waitForPythonExtension ( timeoutMs ) ;
146+ } catch ( e ) {
147+ // eslint-disable-next-line no-console
148+ console . error ( e ) ;
149+ const wb = await browser . getWorkbench ( ) ;
150+ await wb . executeCommand ( "Developer: Reload Window" ) ;
151+ if ( i === retryCount - 1 ) {
152+ throw e ;
153+ }
154+ continue ;
155+ }
156+ break ;
157+ }
158+ }
159+
160+ export async function waitForSyncComplete ( ) {
161+ await browser . waitUntil (
162+ async ( ) => {
163+ const repoConfigItem = await getViewSubSection (
164+ "CONFIGURATION" ,
165+ "Repo"
166+ ) ;
167+ if ( repoConfigItem === undefined ) {
168+ return false ;
169+ }
170+ await repoConfigItem . expand ( ) ;
171+
172+ let status : TreeItem | undefined = undefined ;
173+ for ( const i of await repoConfigItem . getChildren ( ) ) {
174+ if ( ( await i . getLabel ( ) ) . includes ( "State:" ) ) {
175+ status = i ;
176+ break ;
177+ }
178+ }
179+ if ( status === undefined ) {
180+ return false ;
181+ }
182+
183+ const description = await status ?. getDescription ( ) ;
184+ return (
185+ description !== undefined &&
186+ description . includes ( "WATCHING_FOR_CHANGES" )
187+ ) ;
188+ } ,
189+ {
190+ timeout : 60000 ,
191+ interval : 20000 ,
192+ timeoutMsg : "Couldn't finish sync in 1m" ,
193+ }
194+ ) ;
195+ }
196+
197+ export async function startSyncIfStopped ( ) {
198+ browser . waitUntil (
199+ async ( ) => {
200+ const repoConfigItem = await getViewSubSection (
201+ "CONFIGURATION" ,
202+ "Repo"
203+ ) ;
204+ if ( repoConfigItem === undefined ) {
205+ return false ;
206+ }
207+ await repoConfigItem . expand ( ) ;
208+
209+ let status : TreeItem | undefined = undefined ;
210+ for ( const i of await repoConfigItem . getChildren ( ) ) {
211+ if ( ( await i . getLabel ( ) ) . includes ( "State:" ) ) {
212+ status = i ;
213+ break ;
214+ }
215+ }
216+ if ( status === undefined ) {
217+ return false ;
218+ }
219+
220+ if ( ( await status . getDescription ( ) ) ?. includes ( "STOPPED" ) ) {
221+ const buttons = await repoConfigItem . getActionButtons ( ) ;
222+ if ( buttons . length === 0 ) {
223+ return false ;
224+ }
225+ await buttons [ 0 ] . elem . click ( ) ;
226+ }
227+ return true ;
228+ } ,
229+ {
230+ timeout : 20000 ,
231+ }
232+ ) ;
233+ }
0 commit comments