Skip to content

[sourcekit] Fix non-deterministic failure in CompileNotifications tests #17145

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

Conversation

benlangmuir
Copy link
Contributor

@benlangmuir benlangmuir commented Jun 12, 2018

Our notifications are dispatched in the XPC event handler, which is not
synchronized with replies to explicit XPC send_message_with_reply calls.
This is fine for most users of sourcekitd, since the notifications are
already enqueued on the client side, but for testing we need a way to
guarantee that all notifications are passed to the client-side handler
before we exit. This commit introduces a new request for testing that
triggers a notification, allowing the client to wait on that
notification to ensure all previously posted notifications have been
handled.

Note: the non-deterministic test failures can be triggered by adding a
sleep of ~100 ms in the event handler before the notification is
dispatched to the main queue.

Incidentally fix a race in the in-process sourcekit's notification handling
that became more obvious after this change.

rdar://40311995

@benlangmuir
Copy link
Contributor Author

@swift-ci please smoke test

@slavapestov
Copy link
Contributor

Nitpick: typo in commit message ("deterinistic")

@benlangmuir
Copy link
Contributor Author

@swift-ci please smoke test linux

@benlangmuir
Copy link
Contributor Author

benlangmuir commented Jun 13, 2018

The linux failures seem to indicate we're losing this notification in some cases. It may be related to linux using the in-process sourcekitd. Investigating...

This is a test-only change except for the introduction of a new request
that is only used by tests.

Our notifications are dispatched in the XPC event handler, which is not
synchronized with replies to explicit XPC send_message_with_reply calls.
This is fine for most users of sourcekitd, since the notifications are
already enqueued on the client side, but for testing we need a way to
guarantee that all notifications are passed to the client-side handler
before we exit. This commit introduces a new request for testing that
triggers a notification, allowing the client to wait on that
notification to ensure all previously posted notifications have been
handled.

Note: the non-deterministic test failures can be triggered by adding a
sleep of ~100 ms in the event handler before the notification is
dispatched to the main queue.

rdar://40311995
Setting the notification handler was racing with calling it; now both
happen on the same queue. Only affected the in-process sourcekitd.
@benlangmuir benlangmuir force-pushed the notification-test-non-determinism branch from 507d508 to 8902562 Compare June 13, 2018 18:32
@benlangmuir
Copy link
Contributor Author

Sure enough, there was a race in the in-process library (thanks TSan!).

@benlangmuir benlangmuir changed the title [sourcekit] Fix non-deterinistic failure in CompileNotifications tests [sourcekit] Fix non-deterministic failure in CompileNotifications tests Jun 13, 2018
@benlangmuir
Copy link
Contributor Author

@swift-ci please smoke test

@benlangmuir benlangmuir merged commit 4b48f4d into swiftlang:master Jun 13, 2018
@benlangmuir benlangmuir deleted the notification-test-non-determinism branch June 13, 2018 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants