Skip to content

Commit 0ea45c7

Browse files
authored
Merge pull request #287 from benlangmuir/test-serial-fix
[test] Fix notification handler test when run in serial
2 parents 1b5fdce + ce69bb4 commit 0ea45c7

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-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() {}

Utilities/build-script-helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def handle_invocation(swift_exec, args):
101101
env = os.environ
102102
# Set the toolchain used in tests at runtime
103103
env['SOURCEKIT_TOOLCHAIN_PATH'] = args.toolchain
104+
env['INDEXSTOREDB_TOOLCHAIN_BIN_PATH'] = args.toolchain
104105
# Use local dependencies (i.e. checked out next sourcekit-lsp).
105106
if not args.no_local_deps:
106107
env['SWIFTCI_USE_LOCAL_DEPS'] = "1"

0 commit comments

Comments
 (0)