Skip to content

reduce concurrent manifest loading test contention #3954

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
Dec 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,9 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {

// run this with TSAN/ASAN to detect concurrency issues
func testConcurrencyWithWarmup() throws {
let total = 1000
try testWithTemporaryDirectory { path in

let total = 1000
let semaphore = DispatchSemaphore(value: Concurrency.maxOperations)
let manifestPath = path.appending(components: "pkg", "Package.swift")
try localFileSystem.writeFileContents(manifestPath) { stream in
stream <<< """
Expand Down Expand Up @@ -875,6 +875,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {

let sync = DispatchGroup()
for _ in 0 ..< total {
semaphore.wait()
sync.enter()
delegate.prepare(expectParsing: false)
manifestLoader.load(
Expand All @@ -890,7 +891,10 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
observabilityScope: observability.topScope,
on: .global()
) { result in
defer { sync.leave() }
defer {
semaphore.signal()
sync.leave()
}

switch result {
case .failure(let error):
Expand All @@ -915,16 +919,17 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {

// run this with TSAN/ASAN to detect concurrency issues
func testConcurrencyNoWarmUp() throws {
let total = 1000
try testWithTemporaryDirectory { path in

let total = 1000
let semaphore = DispatchSemaphore(value: Concurrency.maxOperations)
let observability = ObservabilitySystem.makeForTesting()
let delegate = ManifestTestDelegate()
let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default, cacheDir: path, delegate: delegate)
let identityResolver = DefaultIdentityResolver()

let sync = DispatchGroup()
for _ in 0 ..< total {
semaphore.wait()
let random = Int.random(in: 0 ... total / 4)
let manifestPath = path.appending(components: "pkg-\(random)", "Package.swift")
if !localFileSystem.exists(manifestPath) {
Expand Down Expand Up @@ -958,7 +963,10 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
observabilityScope: observability.topScope,
on: .global()
) { result in
defer { sync.leave() }
defer {
semaphore.signal()
sync.leave()
}

switch result {
case .failure(let error):
Expand Down