Skip to content

Commit 019d081

Browse files
authored
FoundationEssentialTests: nanosleep is not portable, avoid it (#599)
Use `Thread.sleep(forTimeInterval:)` instead of `nanosleep` which is not a portable sleep primitive. This allows us to build the package tests on Windows.
1 parent e07817c commit 019d081

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Tests/FoundationEssentialsTests/ProcessInfoTests.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,12 @@ final class ProcessInfoTests : XCTestCase {
9494
XCTAssertTrue(memory > 0, "ProcessInfo doesn't think we have any memory")
9595
}
9696

97-
func testSystemUpTime() {
97+
func testSystemUpTime() async throws {
9898
let now = ProcessInfo.processInfo.systemUptime
9999
XCTAssertTrue(
100100
now > 1, "ProcessInfo returned an unrealistically low system uptime")
101101
// Sleep for 0.1s
102-
var ts: timespec = timespec(tv_sec: 0, tv_nsec: 100000000)
103-
nanosleep(&ts, nil)
102+
try await Task.sleep(for: .milliseconds(100))
104103
XCTAssertTrue(
105104
ProcessInfo.processInfo.systemUptime > now,
106105
"ProcessInfo returned the same system uptime with 400")
@@ -172,9 +171,7 @@ final class ProcessInfoTests : XCTestCase {
172171
func testProcessName() {
173172
#if FOUNDATION_FRAMEWORK
174173
let targetName = "TestHost"
175-
#elseif os(Windows)
176-
let targetName = "swift-foundationPackageTests.exe"
177-
#elseif os(Linux)
174+
#elseif os(Linux) || os(Windows)
178175
let targetName = "FoundationPreviewPackageTests.xctest"
179176
#else
180177
let targetName = "xctest"

0 commit comments

Comments
 (0)