Files
swift-nio/Tests/NIOFSTests/FileOpenOptionsTests.swift
Jake PetroulesandGeorge Barnett b07752c676 [Windows] Skip unsupported/flaky tests and run the Windows unit tests in CI (#3680)
### Motivation:

All of the test targets now compile on Windows (#3663, #3665), but
`swift test` doesn't yet pass: a number of tests exercise functionality
that isn't supported or isn't yet functional on Windows, some crash or
hang, and a few are flaky on the WSAPoll-based selector. Before the
Windows unit tests can run in CI, those tests need to be skipped (with
reasons) so a full `swift test` exits cleanly.

### Modifications:

Skip the tests that don't pass on Windows, using `XCTSkip` / Swift
Testing's `.disabled` / a gated `setUp` where a fixture itself traps,
each with a reason. Broadly:

- **Unsupported transports/APIs:** Unix domain sockets, datagram/UDP
channels, pipe channels, raw sockets, vsock, pre-connected sockets, and
`FileRegion` sends.
- **Whole suites** for subsystems that aren't functional on Windows yet,
including the **NIOFileSystem family** (`NIOFSTests`,
`NIOFSIntegrationTests`, `NIOFSFoundationCompatTests`) whose Windows
syscall shims are still stubbed, plus `EchoServerClientTest`,
`ChannelTests`, `DatagramChannelTests`, `StreamChannelTest`,
`FileRegionTest`, `PipeChannelTest`, `RawSocketBootstrapTests`,
`ThreadTest`, and `SocketOptionProviderTest`.
- **Real crashes surfaced by a full run:** `System.enumerateDevices()`
(mis-sized `GetAdaptersAddresses` buffer), the WSAPoll selector trapping
on an invalid fd and on schedule-after-shutdown, and a connection-reset
promise leak.
- **Flaky, timing-sensitive tests:** the event-loop tick-count metrics
tests (the WSAPoll selector wakes far more often than epoll/kqueue).

Then enable the Windows 6.3 + nightly jobs in the reusable unit-tests
workflow (which runs `swift test`) in both the PR and push workflows,
and drop the separate build-only Windows job (which only ran `swift
build --build-tests`).

Windows uses the default `swift test` arguments rather than the Linux
`-Xswiftc -warnings-as-errors` override, because a `#warning` in the
(skipped) stream-channel tests would otherwise fail the build.

All skips are Windows-only; there is no behaviour change on other
platforms.

### Result:

`swift test` passes on Windows, and the Windows unit tests run in CI.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2026-07-29 09:41:53 +01:00

107 lines
4.3 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2023 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
@_spi(Testing) import NIOFS
import XCTest
final class FileOpenOptionsTests: XCTestCase {
override func setUpWithError() throws {
#if os(Windows)
throw XCTSkip("The NIOFileSystem family is not yet functional on Windows")
#endif
}
private let expectedDefaults: FilePermissions = [
.ownerReadWrite,
.groupRead,
.otherRead,
]
func testReadOptions() {
var options = OpenOptions.Read()
XCTAssertEqual(FileDescriptor.OpenOptions(options), [])
options.followSymbolicLinks = false
options.closeOnExec = true
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.noFollow, .closeOnExec])
}
func testDirectoryOptions() {
var options = OpenOptions.Directory()
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.directory])
options.followSymbolicLinks = false
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.noFollow, .directory])
options.followSymbolicLinks = true
options.closeOnExec = true
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.directory, .closeOnExec])
}
func testWriteOpenOrCreate() {
var options = OpenOptions.Write.modifyFile(createIfNecessary: true)
XCTAssertEqual(options.existingFile, .open)
XCTAssertEqual(options.permissionsForRegularFile, self.expectedDefaults)
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.create])
options = OpenOptions.Write.modifyFile(createIfNecessary: true, permissions: .groupExecute)
XCTAssertEqual(options.existingFile, .open)
XCTAssertEqual(options.permissionsForRegularFile, .groupExecute)
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.create])
options.followSymbolicLinks = false
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.create, .noFollow])
}
func testWriteTruncateOrCreate() {
var options = OpenOptions.Write.newFile(replaceExisting: true)
XCTAssertEqual(options.existingFile, .truncate)
XCTAssertEqual(options.permissionsForRegularFile, self.expectedDefaults)
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.create, .truncate])
options = OpenOptions.Write.newFile(replaceExisting: true, permissions: .groupExecute)
XCTAssertEqual(options.existingFile, .truncate)
XCTAssertEqual(options.permissionsForRegularFile, .groupExecute)
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.create, .truncate])
options.followSymbolicLinks = false
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.create, .truncate, .noFollow])
}
func testWriteExclusiveOpen() {
var options = OpenOptions.Write(existingFile: .open, newFile: nil)
XCTAssertEqual(options.existingFile, .open)
XCTAssertNil(options.newFile)
XCTAssertEqual(FileDescriptor.OpenOptions(options), [])
options.followSymbolicLinks = false
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.noFollow])
}
func testWriteExclusiveCreate() {
var options = OpenOptions.Write.newFile(replaceExisting: false)
XCTAssertEqual(options.existingFile, .none)
XCTAssertEqual(options.permissionsForRegularFile, self.expectedDefaults)
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.create, .exclusiveCreate])
options = OpenOptions.Write.newFile(replaceExisting: false, permissions: .groupExecute)
XCTAssertEqual(options.existingFile, .none)
XCTAssertEqual(options.permissionsForRegularFile, .groupExecute)
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.create, .exclusiveCreate])
options.followSymbolicLinks = false
XCTAssertEqual(FileDescriptor.OpenOptions(options), [.create, .exclusiveCreate, .noFollow])
}
}