Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Tests/MongoSwiftSyncTests/SyncChangeStreamTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,17 @@ final class ChangeStreamSpecTests: MongoSwiftTestCase, FailPointConfigured {
}

guard version >= test.minServerVersion else {
print("Skipping tests case \"\(test.description)\": minimum required server " +
print("Skipping test case \"\(test.description)\": minimum required server " +
"version \(test.minServerVersion) not met.")
continue
}

guard !(test.description == "Change Stream should error when _id is projected out" &&
version >= ServerVersion(major: 4, minor: 3, patch: 3)) else {
print("Skipping test case \"\(test.description)\"; see SWIFT-722")
continue
}

print("Executing test: \(test.description)")

try db1.drop()
Expand Down Expand Up @@ -344,6 +350,11 @@ final class SyncChangeStreamTests: MongoSwiftTestCase {
return
}

guard try MongoClient.makeTestClient().serverVersion() < ServerVersion(major: 4, minor: 3, patch: 3) else {
print("Skipping test; see SWIFT-722")
return
}

try withTestNamespace { client, _, coll in
let changeStream = try coll.watch([["$project": ["_id": false]]])
for x in 0..<5 {
Expand Down Expand Up @@ -524,9 +535,15 @@ final class SyncChangeStreamTests: MongoSwiftTestCase {
}
expect(killedAggs.count).to(equal(1))

let version = try MongoClient.makeTestClient().serverVersion()
// the next set of assertions relies on the presence of the NonResumableChangeStreamError label, which was
// introduced in 4.1.1 via SERVER-40446.
guard try MongoClient.makeTestClient().serverVersion() >= ServerVersion(major: 4, minor: 1, patch: 1) else {
guard version >= ServerVersion(major: 4, minor: 1, patch: 1) else {
return
}

// skip on 4.3.3+ due to removal of NonResumableChangeStreamError label; see SWIFT-722
guard version < ServerVersion(major: 4, minor: 3, patch: 3) else {
return
}

Expand Down
14 changes: 14 additions & 0 deletions Tests/MongoSwiftTests/AsyncTestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ extension MongoClient {
XCTFail("Error closing test client: \(error)")
}
}

internal func serverVersion() -> EventLoopFuture<ServerVersion> {
return self.db("admin").runCommand(
["buildInfo": 1],
options: RunCommandOptions(
readPreference: ReadPreference(.primary)
)
).flatMapThrowing { reply in
guard let versionString = reply["version"]?.stringValue else {
throw TestError(message: " reply missing version string: \(reply)")
}
return try ServerVersion(versionString)
}
}
}

extension MongoDatabase {
Expand Down
5 changes: 5 additions & 0 deletions Tests/MongoSwiftTests/ChangeStreamTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ final class ChangeStreamTests: MongoSwiftTestCase {
}

try self.withTestClient { client in
guard try client.serverVersion().wait() < ServerVersion(major: 4, minor: 3, patch: 3) else {
print("Skipping test; see SWIFT-722")
return
}

let db = client.db(type(of: self).testDatabase)
try? db.collection(self.getCollectionName()).drop().wait()
let coll = try db.createCollection(self.getCollectionName()).wait()
Expand Down