@@ -333,7 +333,6 @@ final class BackgroundIndexingTests: XCTestCase {
333
333
}
334
334
335
335
func testBackgroundIndexingStatusWorkDoneProgress( ) async throws {
336
- let workDoneProgressCreated = self . expectation ( description: " Work done progress created " )
337
336
let project = try await SwiftPMTestProject (
338
337
files: [
339
338
" MyFile.swift " : """
@@ -346,32 +345,33 @@ final class BackgroundIndexingTests: XCTestCase {
346
345
capabilities: ClientCapabilities ( window: WindowClientCapabilities ( workDoneProgress: true ) ) ,
347
346
serverOptions: backgroundIndexingOptions,
348
347
preInitialization: { testClient in
349
- testClient. handleSingleRequest { ( request: CreateWorkDoneProgressRequest ) in
350
- workDoneProgressCreated. fulfill ( )
348
+ testClient. handleMultipleRequests { ( request: CreateWorkDoneProgressRequest ) in
351
349
return VoidResponse ( )
352
350
}
353
351
}
354
352
)
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
361
354
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
+ }
367
364
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
370
367
case . end:
371
- didGetEndWorkDoneProgress = true
368
+ if workDoneProgress. token == indexingWorkDoneProgressToken {
369
+ didGetEndWorkDoneProgress = true
370
+ break LOOP
371
+ }
372
372
}
373
- break
374
373
}
374
+ XCTAssertNotNil ( indexingWorkDoneProgressToken, " Expected to receive a work done progress start " )
375
375
XCTAssert ( didGetEndWorkDoneProgress, " Expected end work done progress " )
376
376
377
377
withExtendedLifetime ( project) { }
0 commit comments