Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
ad8e4c8
Changing import in UTR.swift and adding makeAsyncClient
rchhaya Jul 26, 2022
102b400
Changing all imports
rchhaya Jul 26, 2022
9fa5a6b
Async execute + try awaits for operations
rchhaya Jul 26, 2022
c289649
Fully async-ifying and migrating files
rchhaya Jul 26, 2022
a01c138
Print debugging close failures
rchhaya Jul 26, 2022
0a4cf01
Bug on BSON decoder, unbox()
rchhaya Jul 27, 2022
fca3858
Fixing failpont/utils errors, need to fix client deinit
rchhaya Jul 27, 2022
7887707
Remedying package, hanging clients
rchhaya Jul 27, 2022
f0219f4
Entity clients no longer hang, expected errs still fail
rchhaya Jul 28, 2022
dec988e
Problem was with configureFailpoint mLaunch, all pass except ursors c…
rchhaya Jul 28, 2022
c2625b8
Failpoints are closed properly, linted
rchhaya Jul 29, 2022
2a1cd9a
Removing duplicate retrievespectests
rchhaya Jul 29, 2022
4ced5b6
Compiler directives
rchhaya Jul 29, 2022
1de51bf
Compiler directives for users of UTR
rchhaya Jul 29, 2022
55027fe
Failpoint compiler directives
rchhaya Jul 29, 2022
bac6885
Matching compiler directives
rchhaya Jul 29, 2022
e253340
Function compiler directives
rchhaya Jul 29, 2022
778735d
Compilers
rchhaya Jul 29, 2022
8e66be5
More compilers for matching.swift:
rchhaya Jul 29, 2022
4469489
even more compilers for entities
rchhaya Jul 29, 2022
05941a6
Compilers for testfile
rchhaya Jul 29, 2022
0cc50d8
TestWriteModel compiler
rchhaya Jul 29, 2022
08d04c0
Undoing error from prior push:
rchhaya Jul 29, 2022
520a2b2
Closing self-created async client
rchhaya Jul 30, 2022
9a57df0
Taking sharding into account
rchhaya Jul 31, 2022
f99e356
self annotation
rchhaya Jul 31, 2022
33007c0
Closing clients upon sharding thrown err
rchhaya Aug 10, 2022
858b7ab
Flaky entity-find-cursor, operation-failure
rchhaya Aug 10, 2022
5692453
Trying try? to resolve killCursor stuff
rchhaya Aug 11, 2022
659da4c
Linting:
rchhaya Aug 11, 2022
b22084a
Removing print statements but 1 flakyish test:
rchhaya Aug 11, 2022
3268f88
Try await on killing cursors
rchhaya Aug 11, 2022
8e4fe01
Removing prints
rchhaya Aug 11, 2022
78f57f8
Update .swift-version
rchhaya Aug 12, 2022
8886a41
Remnant extra comment:
rchhaya Aug 12, 2022
beb38cb
Merge branch 'SWIFT-1609/utr-async' of github.com:rchhaya/mongo-swift…
rchhaya Aug 12, 2022
f99c747
Update .swift-version
rchhaya Aug 12, 2022
462aba2
Reviewing failpoint, comments, renames, methods, tests, etc.
rchhaya Aug 15, 2022
624a764
Deleting .swift-version
rchhaya Aug 15, 2022
079340e
merge conflicts
rchhaya Aug 15, 2022
597e76a
forgotten commented out compiler directive
rchhaya Aug 15, 2022
82c5163
Undoing setUp() removal for scoping
rchhaya Aug 15, 2022
a222b53
Addressing comments-elg,failpoints,comments,deinits
rchhaya Aug 16, 2022
0d48bf8
Switching order of elg/client shutdown
rchhaya Aug 16, 2022
1c31d13
Apply suggestions from code review
rchhaya Aug 16, 2022
b887bb2
Removing try? for try to see evergreen results
rchhaya Aug 18, 2022
2874160
to try? or not to try?, that is the question
rchhaya Aug 18, 2022
46dfa9e
Specifying command error, docs, and removing imports'
rchhaya Aug 18, 2022
b7369a5
Reusing elg for entities, changing print
rchhaya Aug 19, 2022
697b0d7
remove some unneeded stuff
patrickfreed Aug 29, 2022
c134cbd
Merge remote-tracking branch 'origin/main' into SWIFT-1609/utr-async
patrickfreed Aug 29, 2022
c55c058
Merge remote-tracking branch 'origin/main' into SWIFT-1609/utr-async
patrickfreed Aug 29, 2022
0cdf086
revert to NIOPosix import
patrickfreed Aug 29, 2022
2d8e274
sort imports
patrickfreed Aug 29, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Package.resolved
**/xcuserdata/
.DS_Store
.swift-version
1 change: 0 additions & 1 deletion .swift-version

This file was deleted.

3 changes: 3 additions & 0 deletions Sources/MongoSwift/ClientSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public final class ClientSession {
return false
}

/// Returns whether or not the `pinnedServerAddress` exists.
internal var isPinned: Bool { self.pinnedServerAddress != nil }

/// The client used to start this session.
public let client: MongoClient

Expand Down
105 changes: 105 additions & 0 deletions Sources/TestsCommon/Failpoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import MongoSwift
/// Protocol that test cases which configure fail points during their execution conform to.
public protocol FailPointConfigured {
/// The fail point currently set, if one exists.
var activeFailPoint: FailPoint? { get set }

/// The address of the host in which this failpoint was set on, if applicable.
var targetedHost: ServerAddress? { get set }
}

/// Struct modeling a MongoDB fail point.
///
/// - Note: if a fail point results in a connection being closed / interrupted, libmongoc built in debug mode will print
/// a warning.
public struct FailPoint: Decodable {
public var failPoint: BSONDocument

/// The fail point being configured.
public var name: String {
self.failPoint["configureFailPoint"]?.stringValue ?? ""
}

private init(_ document: BSONDocument) {
self.failPoint = document
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let unordered = try container.decode(BSONDocument.self)
guard let command = unordered["configureFailPoint"] else {
throw DecodingError.dataCorruptedError(
in: container,
debugDescription: "fail point \(unordered) did not contain \"configureFailPoint\" command"
)
}
var ordered: BSONDocument = ["configureFailPoint": command]
for (k, v) in unordered {
guard k != "configureFailPoint" else {
continue
}
ordered[k] = v
}
self.failPoint = ordered
}

/// Enum representing the options for the "mode" field of a `configureFailPoint` command.
public enum Mode {
case times(Int)
case alwaysOn
case off
case activationProbability(Double)

internal func toBSON() -> BSON {
switch self {
case let .times(i):
return ["times": BSON(i)]
case let .activationProbability(d):
return ["activationProbability": .double(d)]
default:
return .string(String(describing: self))
}
}
}

/// Factory function for creating a `failCommand` failpoint.
/// Note: enabling a `failCommand` failpoint will override any other `failCommand` failpoint that is currently
/// enabled.
/// For more information, see the wiki: https://github.com/mongodb/mongo/wiki/The-%22failCommand%22-fail-point
public static func failCommand(
failCommands: [String],
mode: Mode,
blockTimeMS: Int? = nil,
closeConnection: Bool? = nil,
errorCode: Int? = nil,
errorLabels: [String]? = nil,
writeConcernError: BSONDocument? = nil
) -> FailPoint {
var data: BSONDocument = [
"failCommands": .array(failCommands.map { .string($0) })
]
if let blockTime = blockTimeMS {
data["blockTimeMS"] = BSON(blockTime)
data["blockConnection"] = true
}
if let close = closeConnection {
data["closeConnection"] = .bool(close)
}
if let code = errorCode {
data["errorCode"] = BSON(code)
}
if let labels = errorLabels {
data["errorLabels"] = .array(labels.map { .string($0) })
}
if let writeConcernError = writeConcernError {
data["writeConcernError"] = .document(writeConcernError)
}

let command: BSONDocument = [
"configureFailPoint": "failCommand",
"mode": mode.toBSON(),
"data": .document(data)
]
return FailPoint(command)
}
}
10 changes: 0 additions & 10 deletions Tests/MongoSwiftSyncTests/ClientSessionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -516,16 +516,6 @@ final class SyncClientSessionTests: MongoSwiftTestCase {
}
}

func testSessionsUnified() throws {
let tests = try retrieveSpecTestFiles(
specName: "sessions",
subdirectory: "unified",
asType: UnifiedTestFile.self
)
let runner = try UnifiedTestRunner()
try runner.runFiles(tests.map { $0.1 })
}

func testSnapshotSessionsProse() throws {
/// 1. Setting both snapshot and causalConsistency to true is not allowed
try self.withTestNamespace { client, _, _ in
Expand Down
21 changes: 0 additions & 21 deletions Tests/MongoSwiftSyncTests/CrudTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,6 @@ final class CrudTests: MongoSwiftTestCase {
func testWrites() throws {
try self.doTests(forSubdirectory: "v1/write")
}

func testCrudUnified() throws {
let skipFiles: [String] = [
// Skipping because we use bulk-write for these commands and can't pass extra options
// TODO: SWIFT-1429 unskip
"deleteOne-let.json",
"deleteMany-let.json",
"updateOne-let.json",
"updateMany-let.json",
// TODO: SWIFT-1515 unskip
"estimatedDocumentCount-comment.json"
]
let files = try retrieveSpecTestFiles(
specName: "crud",
subdirectory: "unified",
excludeFiles: skipFiles,
asType: UnifiedTestFile.self
)
let runner = try UnifiedTestRunner()
try runner.runFiles(files.map { $0.1 })
}
}

/// A container for the data from a single .json file.
Expand Down
10 changes: 0 additions & 10 deletions Tests/MongoSwiftSyncTests/MongoDatabaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ final class MongoDatabaseTests: MongoSwiftTestCase {
expect(collectionInfo[1]).to(equal(expectedView))
}

func testCreateCollectionUnified() throws {
let tests = try retrieveSpecTestFiles(
specName: "collection-management",
asType: UnifiedTestFile.self
).map { $0.1 }

let runner = try UnifiedTestRunner()
try runner.runFiles(tests)
}

func testListCollections() throws {
let client = try MongoClient.makeTestClient()
let monitor = client.addCommandMonitor()
Expand Down
11 changes: 0 additions & 11 deletions Tests/MongoSwiftSyncTests/RetryableWritesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,4 @@ final class RetryableWritesTests: MongoSwiftTestCase {
}
}
}

func testRetryableWritesUnified() throws {
let tests = try retrieveSpecTestFiles(
specName: "retryable-writes",
subdirectory: "unified",
asType: UnifiedTestFile.self
).map { $0.1 }

let runner = try UnifiedTestRunner()
try runner.runFiles(tests)
}
}
101 changes: 1 addition & 100 deletions Tests/MongoSwiftSyncTests/SpecTestRunner/FailPoint.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import MongoSwiftSync
import TestsCommon

/// Protocol that test cases which configure fail points during their execution conform to.
internal protocol FailPointConfigured {
/// The fail point currently set, if one exists.
var activeFailPoint: FailPoint? { get set }

/// The address of the host in which this failpoint was set on, if applicable.
var targetedHost: ServerAddress? { get set }
}

extension FailPointConfigured {
/// Sets the active fail point to the provided fail point and enables it.
internal mutating func activateFailPoint(
Expand Down Expand Up @@ -51,37 +42,7 @@ class FailPointGuard {
///
/// - Note: if a fail point results in a connection being closed / interrupted, libmongoc built in debug mode will print
/// a warning.
internal struct FailPoint: Decodable {
private var failPoint: BSONDocument

/// The fail point being configured.
internal var name: String {
self.failPoint["configureFailPoint"]?.stringValue ?? ""
}

private init(_ document: BSONDocument) {
self.failPoint = document
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let unordered = try container.decode(BSONDocument.self)
guard let command = unordered["configureFailPoint"] else {
throw DecodingError.dataCorruptedError(
in: container,
debugDescription: "fail point \(unordered) did not contain \"configureFailPoint\" command"
)
}
var ordered: BSONDocument = ["configureFailPoint": command]
for (k, v) in unordered {
guard k != "configureFailPoint" else {
continue
}
ordered[k] = v
}
self.failPoint = ordered
}

extension FailPoint {
internal func enable(
using client: MongoClient,
options: RunCommandOptions? = nil
Expand Down Expand Up @@ -119,64 +80,4 @@ internal struct FailPoint: Decodable {
print("Failed to disable failpoint: \(error)")
}
}

/// Enum representing the options for the "mode" field of a `configureFailPoint` command.
public enum Mode {
case times(Int)
case alwaysOn
case off
case activationProbability(Double)

internal func toBSON() -> BSON {
switch self {
case let .times(i):
return ["times": BSON(i)]
case let .activationProbability(d):
return ["activationProbability": .double(d)]
default:
return .string(String(describing: self))
}
}
}

/// Factory function for creating a `failCommand` failpoint.
/// Note: enabling a `failCommand` failpoint will override any other `failCommand` failpoint that is currently
/// enabled.
/// For more information, see the wiki: https://github.com/mongodb/mongo/wiki/The-%22failCommand%22-fail-point
public static func failCommand(
failCommands: [String],
mode: Mode,
blockTimeMS: Int? = nil,
closeConnection: Bool? = nil,
errorCode: Int? = nil,
errorLabels: [String]? = nil,
writeConcernError: BSONDocument? = nil
) -> FailPoint {
var data: BSONDocument = [
"failCommands": .array(failCommands.map { .string($0) })
]
if let blockTime = blockTimeMS {
data["blockTimeMS"] = BSON(blockTime)
data["blockConnection"] = true
}
if let close = closeConnection {
data["closeConnection"] = .bool(close)
}
if let code = errorCode {
data["errorCode"] = BSON(code)
}
if let labels = errorLabels {
data["errorLabels"] = .array(labels.map { .string($0) })
}
if let writeConcernError = writeConcernError {
data["writeConcernError"] = .document(writeConcernError)
}

let command: BSONDocument = [
"configureFailPoint": "failCommand",
"mode": mode.toBSON(),
"data": .document(data)
]
return FailPoint(command)
}
}
17 changes: 0 additions & 17 deletions Tests/MongoSwiftSyncTests/SyncChangeStreamTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ import TestsCommon
import XCTest

final class SyncChangeStreamTests: MongoSwiftTestCase {
let excludeFiles = [
// TODO: SWIFT-1458 Unskip.
"change-streams-showExpandedEvents.json",
// TODO: SWIFT-1472 Unskip.
"change-streams-pre_and_post_images.json"
]
func testChangeStreamSpecUnified() throws {
let tests = try retrieveSpecTestFiles(
specName: "change-streams",
subdirectory: "unified",
excludeFiles: excludeFiles,
asType: UnifiedTestFile.self
).map { $0.1 }
let testRunner = try UnifiedTestRunner()
try testRunner.runFiles(tests)
}

/// How long in total a change stream should poll for an event or error before returning.
/// Used as a default value for `ChangeStream.nextWithTimeout`
public static let TIMEOUT: TimeInterval = 15
Expand Down
10 changes: 0 additions & 10 deletions Tests/MongoSwiftSyncTests/TransactionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,4 @@ final class TransactionsTests: MongoSwiftTestCase {
try testFile.runTests()
}
}

func testTransactionsUnified() throws {
let files = try retrieveSpecTestFiles(
specName: "transactions",
subdirectory: "unified",
asType: UnifiedTestFile.self
)
let runner = try UnifiedTestRunner()
try runner.runFiles(files.map { $0.1 })
}
}
20 changes: 20 additions & 0 deletions Tests/MongoSwiftTests/ChangeStreamTests.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#if compiler(>=5.5.2) && canImport(_Concurrency)
import Foundation
import MongoSwift
import Nimble
import NIOConcurrencyHelpers
import TestsCommon

@available(macOS 10.15, *)
final class ChangeStreamTests: MongoSwiftTestCase {
func testChangeStreamNext() throws {
try self.withTestClient { client in
Expand Down Expand Up @@ -163,4 +165,22 @@ final class ChangeStreamTests: MongoSwiftTestCase {
expect(try stream.forEach(increment).wait()).to(throwError(errorType: MongoError.LogicError.self))
}
}

func testChangeStreamSpecUnified() async throws {
let excludeFiles = [
// TODO: SWIFT-1458 Unskip.
"change-streams-showExpandedEvents.json",
// TODO: SWIFT-1472 Unskip.
"change-streams-pre_and_post_images.json"
]
let tests = try retrieveSpecTestFiles(
specName: "change-streams",
subdirectory: "unified",
excludeFiles: excludeFiles,
asType: UnifiedTestFile.self
).map { $0.1 }
let testRunner = try await UnifiedTestRunner()
try await testRunner.runFiles(tests)
}
}
#endif
Loading