Skip to content

Commit 1653a8f

Browse files
committed
[test] Fix notification handler test when run in serial
The test was passing with --parallel since each test was being run in its own process, but not when run in serial since other documents could trigger unexpected notifications. Also make the uniqueness of the path reliable using a mutable workspace.
1 parent 8c65878 commit 1653a8f

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ let package = Package(
126126
dependencies: [
127127
"SourceKitD",
128128
"SKCore",
129+
"SKTestSupport",
129130
]
130131
),
131132

Tests/SourceKitDTests/SourceKitDTests.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import SourceKitD
1414
import SKCore
1515
import TSCBasic
1616
import TSCUtility
17+
import ISDBTibs
18+
import ISDBTestSupport
1719
import XCTest
1820

1921
final class SourceKitDTests: XCTestCase {
@@ -31,26 +33,38 @@ final class SourceKitDTests: XCTestCase {
3133
}
3234

3335
func testMultipleNotificationHandlers() {
36+
let ws = try! mutableTibsTestWorkspace(name: "proj1")!
3437
let sourcekitd = try! SourceKitDImpl.getOrCreate(dylibPath: SourceKitDTests.sourcekitdPath)
3538
let keys = sourcekitd.keys
39+
let path: String = ws.testLoc("c").url.path
40+
41+
let isExpectedNotification = { (response: SKDResponse) -> Bool in
42+
if let notification: sourcekitd_uid_t = response.value?[keys.notification],
43+
let name: String = response.value?[keys.name]
44+
{
45+
return name == path && notification == sourcekitd.values.notification_documentupdate
46+
}
47+
return false
48+
}
3649

3750
let expectation1 = expectation(description: "handler 1")
3851
let handler1 = ClosureNotificationHandler { response in
39-
XCTAssertEqual(response.value?[keys.notification], sourcekitd.values.notification_documentupdate)
40-
expectation1.fulfill()
52+
if isExpectedNotification(response) {
53+
expectation1.fulfill()
54+
}
4155
}
4256
sourcekitd.addNotificationHandler(handler1)
4357

4458
let expectation2 = expectation(description: "handler 2")
4559
let handler2 = ClosureNotificationHandler { response in
46-
XCTAssertEqual(response.value?[keys.notification], sourcekitd.values.notification_documentupdate)
47-
expectation2.fulfill()
60+
if isExpectedNotification(response) {
61+
expectation2.fulfill()
62+
}
4863
}
4964
sourcekitd.addNotificationHandler(handler2)
5065

5166
let req = SKDRequestDictionary(sourcekitd: sourcekitd)
5267
req[keys.request] = sourcekitd.requests.editor_open
53-
let path: String = #file
5468
req[keys.name] = path
5569
req[keys.sourcetext] = """
5670
func foo() {}

0 commit comments

Comments
 (0)