@@ -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,57 @@ 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
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
363375 }
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
376+ return data. title == " Indexing "
377+ }
378+ )
379+ receivedBeginProgressNotification. fulfill ( )
380+ guard case . begin( let beginData) = beginNotification. value else {
381+ XCTFail ( " Expected begin notification " )
382+ return
383+ }
384+ XCTAssertEqual ( beginData. message, " Generating build graph " )
385+ let indexingWorkDoneProgressToken = beginNotification. token
386+
387+ let reportNotification = try await project. testClient. nextNotification (
388+ ofType: WorkDoneProgress . self,
389+ satisfying: { notification in
390+ guard notification. token == indexingWorkDoneProgressToken, case . report = notification. value else {
391+ return false
371392 }
393+ return true
372394 }
395+ )
396+ receivedReportProgressNotification. fulfill ( )
397+ guard case . report( let reportData) = reportNotification. value else {
398+ XCTFail ( " Expected report notification " )
399+ return
373400 }
374- XCTAssertNotNil ( indexingWorkDoneProgressToken, " Expected to receive a work done progress start " )
375- XCTAssert ( didGetEndWorkDoneProgress, " Expected end work done progress " )
401+ XCTAssertEqual ( reportData. message, " 0 / 1 " )
402+
403+ _ = try await project. testClient. nextNotification (
404+ ofType: WorkDoneProgress . self,
405+ satisfying: { notification in
406+ guard notification. token == indexingWorkDoneProgressToken, case . end = notification. value else {
407+ return false
408+ }
409+ return true
410+ }
411+ )
376412
377413 withExtendedLifetime ( project) { }
378414 }
0 commit comments