Skip to content

Commit 2faea3f

Browse files
authored
SWIFT-1510 Lower #available checks to run automatic cleanup in deinits to macOS 10.15+ (#747)
1 parent 543984d commit 2faea3f

File tree

7 files changed

+44
-10
lines changed

7 files changed

+44
-10
lines changed

.evergreen/configure-swift.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ if [ "$OS" == "darwin" ]; then
2828
else
2929
sudo xcode-select -s /Applications/Xcode12.app
3030
fi
31+
32+
# TODO SWIFT-1421: remove this once we have new Xcode on Evergreen to test with
33+
export DYLD_LIBRARY_PATH=${SWIFTENV_ROOT}/versions/${SWIFT_VERSION}/usr/lib/swift/macosx/
3134
fi
3235

3336
# switch to current Swift version
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test concurrency APIs on macOS
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
MONGODB_VERSION: 5.0.6
11+
12+
jobs:
13+
test-concurrency:
14+
runs-on: macos-latest
15+
16+
steps:
17+
- name: Check out
18+
uses: actions/checkout@v2
19+
- name: Download MongoDB
20+
run: |
21+
curl https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-${MONGODB_VERSION}.tgz --output mongodb.tgz
22+
tar -xzf mongodb.tgz
23+
- name: Start mongod
24+
run: |
25+
mkdir dbpath
26+
./mongodb-macos-x86_64-${MONGODB_VERSION}/bin/mongod --dbpath dbpath --replSet repl0 &
27+
- name: Initiate replica set
28+
run: |
29+
./mongodb-macos-x86_64-${MONGODB_VERSION}/bin/mongo --eval "rs.initiate()"
30+
- name: Build
31+
run: swift build
32+
- name: Run tests
33+
run: swift test --filter AsyncAwait
34+
env:
35+
MONGODB_TOPOLOGY: replica_set
36+
MONGODB_URI: mongodb://localhost:27017/?replicaSet=repl0

Sources/MongoSwift/ChangeStream.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public class ChangeStream<T: Codable>: CursorProtocol {
288288
/// When concurrency is available, we can ensure change streams are always cleaned up properly.
289289
deinit {
290290
// We can't do this with an @available check on the method; see https://bugs.swift.org/browse/SR-15537.
291-
guard #available(macOS 12, *) else {
291+
guard #available(macOS 10.15, *) else {
292292
return
293293
}
294294
let client = self.client

Sources/MongoSwift/ClientSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public final class ClientSession {
334334
/// Cleans up internal state.
335335
deinit {
336336
#if compiler(>=5.5.2) && canImport(_Concurrency)
337-
if #available(macOS 12, *) {
337+
if #available(macOS 10.15, *) {
338338
// Pull out all necessary values into new references to avoid referencing `self` within the `Task`, since
339339
// the `Task` is going to outlive `self`.
340340
switch self.state {

Sources/MongoSwift/MongoCursor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public class MongoCursor<T: Codable>: CursorProtocol {
272272
/// When concurrency is available, we can ensure cursors are always cleaned up properly.
273273
deinit {
274274
// We can't do this with an @available check on the method; see https://bugs.swift.org/browse/SR-15537.
275-
guard #available(macOS 12, *) else {
275+
guard #available(macOS 10.15, *) else {
276276
return
277277
}
278278
let client = self.client

Tests/MongoSwiftTests/AsyncAwaitTestUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ extension MongoClient {
146146
}
147147
}
148148

149-
@available(macOS 12, *)
149+
@available(macOS 10.15, *)
150150
extension TestCommandMonitor {
151151
/// Capture events that occur while the the provided closure executes.
152152
public func captureEvents<T>(_ f: () async throws -> T) async rethrows -> T {

Tests/MongoSwiftTests/AsyncAwaitTests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#if compiler(>=5.5.2) && canImport(_Concurrency) && os(Linux)
2-
// TODO: SWIFT-1421 remove this comment and the os(Linux) check above. if the described bug is not fixed, we'll need to
3-
// adjust our macOS < 12 testing to skip these tests by providing a filter to `swift test`.
4-
// we shouldn't have to check the operating system here, but there is a bug currently where on older macOS versions
5-
// the @available checks don't work. since we don't have support for macOS 12+ in CI, we can work around this by just
6-
// only defining the tests on Linux for now.
1+
#if compiler(>=5.5.2) && canImport(_Concurrency)
72

83
import Foundation
94
@testable import MongoSwift

0 commit comments

Comments
 (0)