Skip to content

Commit a78e3f3

Browse files
authored
reduce concurrent manifest loading test contention (#3954)
motivation: with manfiest loading async, the concurrent loading tests introduce significant contention on cpu since the underlying queue in unbounded changes: use semaphore to limit the concurrency to max active cpus
1 parent 735ebd1 commit a78e3f3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Tests/PackageLoadingTests/PD_4_2_LoadingTests.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,9 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
827827

828828
// run this with TSAN/ASAN to detect concurrency issues
829829
func testConcurrencyWithWarmup() throws {
830-
let total = 1000
831830
try testWithTemporaryDirectory { path in
832-
831+
let total = 1000
832+
let semaphore = DispatchSemaphore(value: Concurrency.maxOperations)
833833
let manifestPath = path.appending(components: "pkg", "Package.swift")
834834
try localFileSystem.writeFileContents(manifestPath) { stream in
835835
stream <<< """
@@ -875,6 +875,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
875875

876876
let sync = DispatchGroup()
877877
for _ in 0 ..< total {
878+
semaphore.wait()
878879
sync.enter()
879880
delegate.prepare(expectParsing: false)
880881
manifestLoader.load(
@@ -890,7 +891,10 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
890891
observabilityScope: observability.topScope,
891892
on: .global()
892893
) { result in
893-
defer { sync.leave() }
894+
defer {
895+
semaphore.signal()
896+
sync.leave()
897+
}
894898

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

916920
// run this with TSAN/ASAN to detect concurrency issues
917921
func testConcurrencyNoWarmUp() throws {
918-
let total = 1000
919922
try testWithTemporaryDirectory { path in
920-
923+
let total = 1000
924+
let semaphore = DispatchSemaphore(value: Concurrency.maxOperations)
921925
let observability = ObservabilitySystem.makeForTesting()
922926
let delegate = ManifestTestDelegate()
923927
let manifestLoader = ManifestLoader(toolchain: ToolchainConfiguration.default, cacheDir: path, delegate: delegate)
924928
let identityResolver = DefaultIdentityResolver()
925929

926930
let sync = DispatchGroup()
927931
for _ in 0 ..< total {
932+
semaphore.wait()
928933
let random = Int.random(in: 0 ... total / 4)
929934
let manifestPath = path.appending(components: "pkg-\(random)", "Package.swift")
930935
if !localFileSystem.exists(manifestPath) {
@@ -958,7 +963,10 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
958963
observabilityScope: observability.topScope,
959964
on: .global()
960965
) { result in
961-
defer { sync.leave() }
966+
defer {
967+
semaphore.signal()
968+
sync.leave()
969+
}
962970

963971
switch result {
964972
case .failure(let error):

0 commit comments

Comments
 (0)