Skip to content

[test] Fix notification handler test when run in serial #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ let package = Package(
dependencies: [
"SourceKitD",
"SKCore",
"SKTestSupport",
]
),

Expand Down
24 changes: 19 additions & 5 deletions Tests/SourceKitDTests/SourceKitDTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import SourceKitD
import SKCore
import TSCBasic
import TSCUtility
import ISDBTibs
import ISDBTestSupport
import XCTest

final class SourceKitDTests: XCTestCase {
Expand All @@ -31,26 +33,38 @@ final class SourceKitDTests: XCTestCase {
}

func testMultipleNotificationHandlers() {
let ws = try! mutableTibsTestWorkspace(name: "proj1")!
let sourcekitd = try! SourceKitDImpl.getOrCreate(dylibPath: SourceKitDTests.sourcekitdPath)
let keys = sourcekitd.keys
let path: String = ws.testLoc("c").url.path

let isExpectedNotification = { (response: SKDResponse) -> Bool in
if let notification: sourcekitd_uid_t = response.value?[keys.notification],
let name: String = response.value?[keys.name]
{
return name == path && notification == sourcekitd.values.notification_documentupdate
}
return false
}

let expectation1 = expectation(description: "handler 1")
let handler1 = ClosureNotificationHandler { response in
XCTAssertEqual(response.value?[keys.notification], sourcekitd.values.notification_documentupdate)
expectation1.fulfill()
if isExpectedNotification(response) {
expectation1.fulfill()
}
}
sourcekitd.addNotificationHandler(handler1)

let expectation2 = expectation(description: "handler 2")
let handler2 = ClosureNotificationHandler { response in
XCTAssertEqual(response.value?[keys.notification], sourcekitd.values.notification_documentupdate)
expectation2.fulfill()
if isExpectedNotification(response) {
expectation2.fulfill()
}
}
sourcekitd.addNotificationHandler(handler2)

let req = SKDRequestDictionary(sourcekitd: sourcekitd)
req[keys.request] = sourcekitd.requests.editor_open
let path: String = #file
req[keys.name] = path
req[keys.sourcetext] = """
func foo() {}
Expand Down
1 change: 1 addition & 0 deletions Utilities/build-script-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def handle_invocation(swift_exec, args):
env = os.environ
# Set the toolchain used in tests at runtime
env['SOURCEKIT_TOOLCHAIN_PATH'] = args.toolchain
env['INDEXSTOREDB_TOOLCHAIN_BIN_PATH'] = args.toolchain
# Use local dependencies (i.e. checked out next sourcekit-lsp).
if not args.no_local_deps:
env['SWIFTCI_USE_LOCAL_DEPS'] = "1"
Expand Down