-
Notifications
You must be signed in to change notification settings - Fork 314
Simplify tests #896
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
Simplify tests #896
Conversation
- Remove the JSONRPC connection kind between `TestSourceKitServer` and `SourceKitServer` - It wasn’t actually used and the connection abstraction just made things more complicated than they needed to be - Send requests and notifications to `SourceKitServer` by directly calling into `SourceKitServer.handle` instead of going through a `Connection`. This makes the code a lot easier to understand statically - Make `TestSourceKitServer` conform to `MessageHandler` instead of going through `TestClient` - IMO this centralizes all the handling and makes it a lot easier to follow. `TestClient` didn’t do a whole bunch anyway. - Allow async awaiting of next notifications instead of having to register a `handleNextNotification` handler before expecting the notification to be emitted. - This allows us to remove quite a few `XCTExpectation`s in test cases - Change `sendSync` function that sends a request and returns the result to be `async`
Really, what the class was mocking is a SourceKit-LSP client.
…eKitServer.Options` Really, these options had nothing to do with `TestSourceKitLSPClient`, they are just the defaults that are used for all the tests.
It turns out that `XCTestCase.setUp` can indeed be `async` and we thus don’t actually need `awaitTask`
@swift-ci Please test |
// FIXME: (async) We need more granular request handling. Completion requests | ||
// to the same file depend on each other because we only have one global | ||
// code completion session in sourcekitd but they don't need to be full | ||
// barriers to any other 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.
If there's only the one session, doesn't that mean all completion requests (even across files) have to depend on each other? What happens today if multiple are sent?
We could also just make it an error to request completion when there's already a completion happening.
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.
Let’s discuss any of the code completion scheduling on #899.
Apologies for the large diff but all the changes are fairly straightforward and intertwined so it doesn’t make too much sense to split them up.
The goal of this PR is to simplify the API of
TestSourceKitServer
SourceKitServer
by directly calling intoSourceKitServer.handle
instead of going through aConnection
. This makes the code a lot easier to understand staticallyTestSourceKitServer
conform toMessageHandler
instead of going throughTestClient
TestClient
didn’t do a whole bunch anyway.sendSync
function that sends a request and returns the result to beasync
handleNextNotification
handler before expecting the notification to be emitted.XCTExpectation
s in test casesTestSourceKitServer
andSourceKitServer
TestSourceKitServer
toTestSourceKitClient
because really, it’s mocking an LSP client and isn’t modeling a server.While doing this refactoring, I discovered a race condition where two code completion requests could be executed concurrently, causing conflicts because
sourcekitd
only has a single, global code completion session. I hot-fixed this for now by making code completion requests barriers in the message handling queue. The real fix is #899.