Skip to content

Fix test failures after merging rebranch #923

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 1 commit into from
Oct 26, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 25, 2023

AFAICT, when chainging build settings clangd now provides two PublishDiagnosticNotifications: One with the diagnostics that were still computed from the old build settings, followed by a notification that contains the diagnostics for the new build settings.

Relax the tests so that we don’t expect the next diagnsotics notification to contain the the updated diagnostics but just expect to receive any diagnostic notification within a timeout that contains the updated diagnostics.

rdar://115435598

AFAICT, when chainging build settings `clangd` now provides two `PublishDiagnosticNotifications`: One with the diagnostics that were still computed from the old build settings, followed by a notification that contains the diagnostics for the new build settings.

Relax the tests so that we don’t expect the *next* diagnsotics notification to contain the the updated diagnostics but just expect to receive any diagnostic notification within a timeout that contains the updated diagnostics.

rdar://115435598
@ahoppen
Copy link
Member Author

ahoppen commented Oct 25, 2023

@swift-ci Please test

await buildSystem.delegate?.fileBuildSettingsChanged([doc])

try await fulfillmentOfOrThrow([expectation])
var receivedCorrectDiagnostic = false
for _ in 0..<Int(defaultTimeout) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems kind of weird to me to base this on timeout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me. We wait 1 second for each notification and iterate this defaultTimeout times. That means that we wait for the correct diagnostic notification defaultTimeout seconds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which only works if the number of notifications received is < defaultTimeout in seconds. Right now there's 2 so that's fine, but that's why it feels odd to me - the number of notifications we allow is dependent on the timeout value, rather than just receiving notifications up to a timeout/successful notification.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the assumption is that number of notifications received ≪ default timeout. I think that’s a fair assumption to make. Happy to change it to 0..<30 though, like we do in other test case.

var receivedCorrectDiagnostic = false
for _ in 0..<Int(defaultTimeout) {
let refreshedDiags = try await testClient.nextDiagnosticsNotification(timeout: 1)
if refreshedDiags.diagnostics.count == 0, text == documentManager.latestSnapshot(doc)!.text {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the document snapshot even tested in these tests 🤔?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably to check that we get no diagnostics for the expected source file contents and not, e.g. no diagnostics because the file is empty. I probably wouldn’t have checked it if I wrote the test but 🤷🏽

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that's not even what that is testing, unless I'm misunderstanding it. All it's checking is that our state in document manager matches what we expect, which isn't really anything to do with diagnostics.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to remove the check if you care.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you can actually see a reason for it, IMO it just confuses what the test is testing. So yeah, I'd be in favor of removing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to leave it, but can you throw in a comment saying why we're doing this? Preferably with a link to the radar about fixing this in clangd, since it really does seem like a bug.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven’t been able to find a good clangd reproducer yet outside of this test case, so this might actually be a race within the test itself. Since I want to re-write these tests with the new test workspace infrastructure anyway, I’ll leave it as-is for now and will add a comment to a clangd bug if the issue still persists with the new test infrastructure.

@ahoppen ahoppen merged commit 139b69a into swiftlang:main Oct 26, 2023
@ahoppen ahoppen deleted the ahoppen/rebranch-failures branch October 26, 2023 19:00
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.

3 participants