@@ -3,10 +3,15 @@ import Foundation
33import Nimble
44import XCTest
55
6- /// Struct representing a single test within a spec test JSON file.
7- private struct RetryableWritesTest : Decodable , SpecTest {
6+ /// Struct representing a single test within a retryable-writes spec test JSON file.
7+ private struct RetryableWritesTest : Decodable {
8+ /// Description of the test.
89 let description : String
10+
11+ /// The expected outcome of executing the operation.
912 let outcome : TestOutcome
13+
14+ /// The operation to execute as part of this test case.
1015 let operation : AnyTestOperation
1116
1217 /// Options used to configure the `SyncMongoClient` used for this test.
@@ -67,12 +72,12 @@ final class RetryableWritesTests: MongoSwiftTestCase, FailPointConfigured {
6772
6873 if let requirements = testFile. runOn {
6974 guard requirements. contains ( where: { $0. isMet ( by: version, MongoSwiftTestCase . topologyType) } ) else {
70- print ( " Skipping tests from file \( fileName) , deployment requirements not met. " )
75+ fileLevelLog ( " Skipping tests from file \( fileName) , deployment requirements not met. " )
7176 continue
7277 }
7378 }
7479
75- print ( " \n ------------ \n Executing tests from file \( fileName) ... \n " )
80+ fileLevelLog ( " Executing tests from file \( fileName) ... \n " )
7681 for test in testFile. tests {
7782 print ( " Executing test: \( test. description) " )
7883
@@ -90,7 +95,35 @@ final class RetryableWritesTests: MongoSwiftTestCase, FailPointConfigured {
9095 }
9196 defer { self . disableActiveFailPoint ( ) }
9297
93- try test. run ( client: client, db: db, collection: collection, session: nil )
98+ var result : TestOperationResult ?
99+ var seenError : Error ?
100+
101+ do {
102+ result = try test. operation. execute ( on: . collection( collection) , session: nil )
103+ } catch {
104+ if case let ServerError . bulkWriteError( _, _, _, bulkResult, _) = error {
105+ result = TestOperationResult ( from: bulkResult)
106+ }
107+ seenError = error
108+ }
109+
110+ if test. outcome. error ?? false {
111+ expect ( seenError) . toNot ( beNil ( ) , description: test. description)
112+ } else {
113+ expect ( seenError) . to ( beNil ( ) , description: test. description)
114+ }
115+
116+ if let expectedResult = test. outcome. result {
117+ expect ( result) . toNot ( beNil ( ) )
118+ expect ( result) . to ( equal ( expectedResult) )
119+ }
120+
121+ let verifyColl = db. collection ( test. outcome. collection. name ?? collection. name)
122+ let foundDocs = try Array ( verifyColl. find ( ) )
123+ expect ( foundDocs. count) . to ( equal ( test. outcome. collection. data. count) )
124+ zip ( foundDocs, test. outcome. collection. data) . forEach {
125+ expect ( $0) . to ( sortedEqual ( $1) , description: test. description)
126+ }
94127 }
95128 }
96129 }
0 commit comments