@@ -333,6 +333,21 @@ final class BackgroundIndexingTests: XCTestCase {
333333 }
334334
335335 func testBackgroundIndexingStatusWorkDoneProgress( ) async throws {
336+ let receivedBeginProgressNotification = self . expectation (
337+ description: " Received work done progress saying build graph generation "
338+ )
339+ let receivedReportProgressNotification = self . expectation (
340+ description: " Received work done progress saying indexing "
341+ )
342+ var serverOptions = backgroundIndexingOptions
343+ serverOptions. indexTestHooks = IndexTestHooks (
344+ buildGraphGenerationDidFinish: {
345+ await self . fulfillment ( of: [ receivedBeginProgressNotification] , timeout: defaultTimeout)
346+ } ,
347+ updateIndexStoreTaskDidFinish: { _ in
348+ await self . fulfillment ( of: [ receivedReportProgressNotification] , timeout: defaultTimeout)
349+ }
350+ )
336351 let project = try await SwiftPMTestProject (
337352 files: [
338353 " MyFile.swift " : """
@@ -343,36 +358,55 @@ final class BackgroundIndexingTests: XCTestCase {
343358 """
344359 ] ,
345360 capabilities: ClientCapabilities ( window: WindowClientCapabilities ( workDoneProgress: true ) ) ,
346- serverOptions: backgroundIndexingOptions,
361+ serverOptions: serverOptions,
362+ pollIndex: false ,
347363 preInitialization: { testClient in
348364 testClient. handleMultipleRequests { ( request: CreateWorkDoneProgressRequest ) in
349365 return VoidResponse ( )
350366 }
351367 }
352368 )
353- var indexingWorkDoneProgressToken : ProgressToken ? = nil
354- var didGetEndWorkDoneProgress = false
355- // Loop terminates when we see the work done end progress or if waiting for the next notification times out
356- LOOP: while true {
357- let workDoneProgress = try await project. testClient. nextNotification ( ofType: WorkDoneProgress . self)
358- switch workDoneProgress. value {
359- case . begin( let data) :
360- if data. title == " Indexing " {
361- XCTAssertNil ( indexingWorkDoneProgressToken, " Received multiple work done progress notifications for indexing " )
362- indexingWorkDoneProgressToken = workDoneProgress. token
363- }
364- case . report:
365- // We ignore progress reports in the test because it's non-deterministic how many we get
366- break
367- case . end:
368- if workDoneProgress. token == indexingWorkDoneProgressToken {
369- didGetEndWorkDoneProgress = true
370- break LOOP
369+
370+ let beginNotification = try await project. testClient. nextNotification (
371+ ofType: WorkDoneProgress . self,
372+ satisfying: { notification in
373+ guard case . begin( let data) = notification. value else {
374+ return false
371375 }
376+ return data. title == " Indexing "
372377 }
378+ )
379+ receivedBeginProgressNotification. fulfill ( )
380+ guard case . begin( let beginData) = beginNotification. value else {
381+ XCTFail ( " Expected begin notification " )
382+ return
373383 }
374- XCTAssertNotNil ( indexingWorkDoneProgressToken, " Expected to receive a work done progress start " )
375- XCTAssert ( didGetEndWorkDoneProgress, " Expected end work done progress " )
384+ XCTAssertEqual ( beginData. message, " Generating build graph " )
385+ let indexingWorkDoneProgressToken = beginNotification. token
386+
387+ _ = try await project. testClient. nextNotification (
388+ ofType: WorkDoneProgress . self,
389+ satisfying: { notification in
390+ guard notification. token == indexingWorkDoneProgressToken,
391+ case . report( let reportData) = notification. value,
392+ reportData. message == " 0 / 1 "
393+ else {
394+ return false
395+ }
396+ return true
397+ }
398+ )
399+ receivedReportProgressNotification. fulfill ( )
400+
401+ _ = try await project. testClient. nextNotification (
402+ ofType: WorkDoneProgress . self,
403+ satisfying: { notification in
404+ guard notification. token == indexingWorkDoneProgressToken, case . end = notification. value else {
405+ return false
406+ }
407+ return true
408+ }
409+ )
376410
377411 withExtendedLifetime ( project) { }
378412 }
0 commit comments