@@ -333,7 +333,6 @@ final class BackgroundIndexingTests: XCTestCase {
333333 }
334334
335335 func testBackgroundIndexingStatusWorkDoneProgress( ) async throws {
336- let workDoneProgressCreated = self . expectation ( description: " Work done progress created " )
337336 let project = try await SwiftPMTestProject (
338337 files: [
339338 " MyFile.swift " : """
@@ -346,32 +345,33 @@ final class BackgroundIndexingTests: XCTestCase {
346345 capabilities: ClientCapabilities ( window: WindowClientCapabilities ( workDoneProgress: true ) ) ,
347346 serverOptions: backgroundIndexingOptions,
348347 preInitialization: { testClient in
349- testClient. handleSingleRequest { ( request: CreateWorkDoneProgressRequest ) in
350- workDoneProgressCreated. fulfill ( )
348+ testClient. handleMultipleRequests { ( request: CreateWorkDoneProgressRequest ) in
351349 return VoidResponse ( )
352350 }
353351 }
354352 )
355- try await fulfillmentOfOrThrow ( [ workDoneProgressCreated] )
356- let workBeginProgress = try await project. testClient. nextNotification ( ofType: WorkDoneProgress . self)
357- guard case . begin = workBeginProgress. value else {
358- XCTFail ( " Expected begin work done progress " )
359- return
360- }
353+ var indexingWorkDoneProgressToken : ProgressToken ? = nil
361354 var didGetEndWorkDoneProgress = false
362- for _ in 0 ..< 5 {
363- let workEndProgress = try await project. testClient. nextNotification ( ofType: WorkDoneProgress . self)
364- switch workEndProgress. value {
365- case . begin:
366- XCTFail ( " Unexpected begin work done progress " )
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+ }
367364 case . report:
368- // Allow up to 2 work done progress reports.
369- continue
365+ // We ignore progress reports in the test because it's non-deterministic how many we get
366+ break
370367 case . end:
371- didGetEndWorkDoneProgress = true
368+ if workDoneProgress. token == indexingWorkDoneProgressToken {
369+ didGetEndWorkDoneProgress = true
370+ break LOOP
371+ }
372372 }
373- break
374373 }
374+ XCTAssertNotNil ( indexingWorkDoneProgressToken, " Expected to receive a work done progress start " )
375375 XCTAssert ( didGetEndWorkDoneProgress, " Expected end work done progress " )
376376
377377 withExtendedLifetime ( project) { }
0 commit comments