-
Notifications
You must be signed in to change notification settings - Fork 314
Wait for cancellation to propagate in testDontReturnEmptyDiagnosticsIfDiagnosticRequestIsCancelled
#1412
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
Wait for cancellation to propagate in testDontReturnEmptyDiagnosticsIfDiagnosticRequestIsCancelled
#1412
Conversation
@swift-ci Please test |
// `log(request:)` is called in `SourceKitD.send` before the request is sent, so we're hooking in here. | ||
testHooks.sourcekitdRequestDidStart?(request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to put this in func send
? I guess to avoid exposing it in the protocol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking because protocols can’t have stored properties. But somehow didn’t occur to me before that we could just make the test hooks a protocol requirement… 🤦🏽
420dc8a
to
03b8a8a
Compare
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
…IfDiagnosticRequestIsCancelled` I saw a few non-deterministic test failures. I think the issue was that handling of the `CancelRequestNotification` is done asynchronously, which left a short window in which the sourcekitd diagnostics request could run and return results instead of being cancelled. Wait for the diagnostic request to actually be cancelled before running it for real. While doing this, also introduce proper sourcekitd test hooks instead of relying on the preparation test hooks, which just got run as a side effect.
03b8a8a
to
37e6a8a
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
Turns out that sourcekitd test hooks were a bad idea because of the following comment that I wrote: ``` `testHooks` are only considered when an instance is being created. If a sourcekitd instance at the given path already exists, its test hooks will be used. ``` During test execution in Xcode, we generate a bunch of `SourceKitServer` instances in the same process that all call `DynamicallyLoadedSourceKitD.getOrCreate`. Now, if `testDontReturnEmptyDiagnosticsIfDiagnosticRequestIsCancelled` is not the first test being executed in the process (which usually it is not), the test hooks in it won’t get used. Switch back to using the preparation hooks, essentially reverting swiftlang#1412 and keeping the following snippet to fix the underlying issue ```swift // Poll until the `CancelRequestNotification` has been propagated to the request handling. for _ in 0..<Int(defaultTimeout * 100) { if Task.isCancelled { break } usleep(10_000) } ```
I saw a few non-deterministic test failures. I think the issue was that handling of the
CancelRequestNotification
is done asynchronously, which left a short window in which the sourcekitd diagnostics request could run and return results instead of being cancelled. Wait for the diagnostic request to actually be cancelled before running it for real.While doing this, also introduce proper sourcekitd test hooks instead of relying on the preparation test hooks, which just got run as a side effect.