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

tests: Fix EndToEnd test deadlock under swift test, but exclude from CI #144

Merged
merged 6 commits into from
Nov 11, 2024

Conversation

euanh
Copy link
Contributor

@euanh euanh commented Nov 5, 2024

Building an SDK requires running the sdk-generator with swift run swift-sdk-generator. This takes a lock on .build, but if the tests are being run by swift test the outer Swift Package Manager instance will already hold this lock, causing the test to deadlock. We can avoid this by giving the swift run swift-sdk-generator instance its own scratch directory.

This PR consolidates the code which builds SDKs in one function, then runs each SDK build with its own temporary scratch directory. This avoids the deadlock on the .build directory when run under swift test.

The tests continue to pass when run under Xcode, which was not affected by the deadlock because it works in a separate scratch directory.

⚠️ The tests cannot currently run in CI because SDK generator cannot use the HTTP proxy to download packages. This PR allows the tests to be run locally with swift test but skips them when running in the CI. When the downloading problem is solved, the tests can be enabled in CI as well.

⚠️ RHEL-based Swift 6.0 SDKs built from container images currently do not currently work, as reported in #138. This PR makes it possible to run the test locally under swift test while working on this problem, to prevent regressions such as #141.

Fixes #143

@euanh euanh force-pushed the endtoend-test-deadlock branch 15 times, most recently from 9eb63de to 790c17d Compare November 8, 2024 09:16
euanh added 2 commits November 8, 2024 14:45
The EndToEnd tests build SDKs in several places.   This commit
consolidates this duplicated code in one function.   This makes
it easier for the next commit to give each build a temporary
scratch directory, which will fix the problem of the tests
deadlocking when run under `swift test`.
@euanh euanh force-pushed the endtoend-test-deadlock branch 7 times, most recently from dd7f401 to 6a26b1e Compare November 11, 2024 09:10
Building an SDK requires running the sdk-generator with `swift run
swift-sdk-generator`.  This takes a lock on `.build`, but if the
tests are being run by `swift test` the outer Swift Package Manager
instance will already hold this lock, causing the test to deadlock.
We can work around this by giving the `swift run swift-sdk-generator`
instance its own scratch directory.
…xecutable

`testPackageInitExecutable` checks that the default Swift package generated
by `swift package init` can be built with each SDK under test.    The packages
are already generated in temporary directories, so they do not suffer from the
deadlocking problem when run under `swift test`.

Currently each test run uses a directory with the same name in the
user's temporary directory.   This means that the test has to remove
anything left behind by a previous run before starting a new on.
Using `withTemporaryDirectory` avoids this problem because it creates
a fresh temporary directory for each run and deletes it automatically
when the body closure returns.
@euanh euanh force-pushed the endtoend-test-deadlock branch from 6a26b1e to ccb2a9b Compare November 11, 2024 09:21
The EndToEnd tests no longer deadlock under `swift test` and can
now be run on macOS and Linux.

The CI cannot currently run the end to end tests because SDK generator
cannot use the CI HTTP proxy to download packages.   This commit
explicitly skips the tests when running under CI.

The tests can be run under macOS and Linux for local testing.

Fixes: swiftlang#143
Packages.gz for jammy-updates now expands to more than 10MB.
With the previous buffer size, ProcessExecutor.TooMuchProcessOutputError
would be thrown when unpacking this file.
@euanh euanh force-pushed the endtoend-test-deadlock branch from ccb2a9b to 8bd80df Compare November 11, 2024 17:09
@euanh
Copy link
Contributor Author

euanh commented Nov 11, 2024

@swift-ci test

@euanh euanh marked this pull request as ready for review November 11, 2024 17:12
@euanh euanh requested a review from MaxDesiatov as a code owner November 11, 2024 17:12
@euanh euanh changed the title tests: Fix EndToEnd test deadlock under swift test and enable tests on macOS tests: Fix EndToEnd test deadlock under swift test, but exclude from CI Nov 11, 2024
@euanh
Copy link
Contributor Author

euanh commented Nov 11, 2024

I may need to refactor these tests more when I start on #138, but this PR should at least let them run and pass in local testing for now.

@euanh euanh merged commit 9071f98 into swiftlang:main Nov 11, 2024
3 checks passed
@euanh euanh deleted the endtoend-test-deadlock branch November 11, 2024 18:03
@euanh euanh added the test suite Changes to generator's test suite label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test suite Changes to generator's test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EndToEnd tests deadlock when run at the command line with swift test
2 participants