Skip to content

Commit 727835f

Browse files
authored
increase amount of open files for code coverage (#129)
1 parent 6a0dd8c commit 727835f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Sources/DatadogSDKTesting/Coverage/DDCoverageHelper.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class DDCoverageHelper {
3737
coverageWorkQueue = OperationQueue()
3838
coverageWorkQueue.qualityOfService = .utility
3939
coverageWorkQueue.maxConcurrentOperationCount = max(ProcessInfo.processInfo.activeProcessorCount - 1, 1)
40+
setFileLimit()
4041
}
4142

4243
func clearCounters() {
@@ -47,6 +48,23 @@ class DDCoverageHelper {
4748
$0.endCountersFuncPtr)
4849
}
4950
}
51+
52+
private func setFileLimit() {
53+
var limit = rlimit()
54+
let filesMax = 4096
55+
guard getrlimit(RLIMIT_NOFILE, &limit) == 0 else {
56+
Log.debug("Can't get open file limit")
57+
return
58+
}
59+
guard limit.rlim_cur < filesMax else { return }
60+
limit.rlim_cur = rlim_t(filesMax)
61+
limit.rlim_max = rlim_t(filesMax * 8)
62+
if setrlimit(RLIMIT_NOFILE, &limit) == 0 {
63+
Log.debug("Updated open file limit to \(filesMax)")
64+
} else {
65+
Log.debug("Can't increase open file limit")
66+
}
67+
}
5068

5169
func setTest(name: String, testSessionId: UInt64, testSuiteId: UInt64, spanId: UInt64) {
5270
if !self.initialCoverageSaved {

Sources/EventsExporter/CoverageExporter/CoverageExporter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal class CoverageExporter {
6363
do {
6464
profData = try DDCoverageConversor.generateProfData(profrawFile: coverage)
6565
} catch {
66-
Log.print("Profiler Data genetation failed: \(error)")
66+
Log.print("Profiler Data generation failed: \(error)")
6767
return
6868
}
6969

Sources/EventsExporter/Utils/Spawn.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public enum Spawn {
5151

5252
var childActions: posix_spawn_file_actions_t?
5353
dd_posix_spawn_file_actions_init(&childActions)
54-
defer { dd_posix_spawn_file_actions_destroy(&childActions) }
5554

5655
let outFile: URL?
5756
let errFile: URL?
@@ -85,6 +84,8 @@ public enum Spawn {
8584
dd_posix_spawn(&pid, command, &childActions, nil, argv, nil)
8685
}
8786

87+
dd_posix_spawn_file_actions_destroy(&childActions)
88+
8889
do {
8990
try _wait(spawn: ret, pid: pid)
9091
} catch let e as RunErrorCode {

0 commit comments

Comments
 (0)