Skip to content
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

Fix occasional race conditions when testing #414

Closed

Conversation

jaywardell
Copy link
Contributor

When testing in Xcode, I was encountering an occasional crash that was happening when other tests were being run (tests other than mine).

Screenshot 2025-01-28 at 10 24 31 AM

They appear to be related to these tests not calling PublishingContext.initialize() before calling render(), though actually there are a few other tests that don't call PublishingContext.initialize() before calling render() and don't seem to cause this issue.

This behavior can be reproduced pretty reliably by control-clicking the test button on line 14 of IncludeTests in Include.swift and choosing "Run 'Include Tests' Repeatedly…"
Run 'Include Tests'

As I say, there are a few tests that can cause this crash, and it's flakey exactly when it will happen.

Still, by calling try PublishingContext.initialize(for: TestSite(), from: #filePath) on init, this crash can be avoided. This is at least the approach that others have used in tests like SubsiteLinkTests in Link.swift.

So I added this to a few tests that seem to cause this crash for me. If others encounter this with other tests, they can feel free to copy this approach.

jaywardell and others added 4 commits January 27, 2025 23:22
update from main branch
merge from two straws main
…ce condition involving PublishingContext.default not having been initialized.

calling PublishingContext.initialize() fixed this
…ce condition involving PublishingContext.default not having been initialized.

calling PublishingContext.initialize() fixed this
@twostraws
Copy link
Owner

Thank you! We've used this init() solution elsewhere, and it's really flaky – so easy to forget, and so damaging. While we think up a better solution we'll need to proceed with this. Did it pass SwiftLint okay?

@JPToroDev
Copy link
Collaborator

I've got a fix to this janky init() hack we've been using. Will push shortly.

@jaywardell
Copy link
Contributor Author

jaywardell commented Jan 29, 2025

I had forgotten to run SwiftLint on this PR. Sorry.

It looks like this is probably moot given #420. It should go without saying, but feel free to give that PR priority and close this one if it's not needed.

@JPToroDev
Copy link
Collaborator

I'm going to close this PR since #420 introduces a long-term solution. Excited to get your other PRs across the finish line!

@JPToroDev JPToroDev closed this Jan 29, 2025
@jaywardell
Copy link
Contributor Author

👍

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