Skip to content

Commit

Permalink
migrate Fsync tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tayloraswift committed Oct 24, 2024
1 parent 44db06f commit 5b97627
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
35 changes: 0 additions & 35 deletions Sources/MongoDBTests/Fsync/Fsync.swift

This file was deleted.

2 changes: 0 additions & 2 deletions Sources/MongoDBTests/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ enum Main:TestMain
static
let all:[any TestBattery.Type] =
[
Fsync <ReplicatedConfiguration>.self,
Indexes <ReplicatedConfiguration>.self,

Transactions <ReplicatedConfiguration>.self,


Fsync <SingleConfiguration>.self,
Indexes <SingleConfiguration>.self,
]
}
7 changes: 1 addition & 6 deletions Sources/MongoDBTests2/Cursors.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import MongoDB
import Testing

extension Tag
{
@Tag static var cursors:Self
}

@Suite(.tags(.cursors))
@Suite
struct Cursors
{
let collection:Mongo.Collection = "Ordinals"
Expand Down
40 changes: 40 additions & 0 deletions Sources/MongoDBTests2/Fsync.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import MongoDB
import Testing

@Suite
struct Fsync
{
@Test(arguments: [.single, .replicated] as [any Mongo.TestConfiguration])
func fsync(_ configuration:any Mongo.TestConfiguration) async throws
{
let bootstrap:Mongo.DriverBootstrap = configuration.bootstrap(on: .singleton)
try await bootstrap.withSessionPool(logger: .init(level: .error))
{
try await self.run(with: $0)
}
}

func run(with pool:Mongo.SessionPool) async throws
{
// We should ensure we are locking and unlocking the same node!
let node:Mongo.ReadPreference = .nearest(tagSets: [["name": "A"]])

var lock:Mongo.FsyncLock

lock = try await pool.run(command: Mongo.Fsync.init(lock: true),
against: .admin,
on: node)

#expect(lock.count == 1)

// We should always be able to run the ping command, even if the
// node is write-locked.
try await pool.run(command: Mongo.Ping.init(), against: .admin, on: node)

lock = try await pool.run(command: Mongo.FsyncUnlock.init(),
against: .admin,
on: node)

#expect(lock.count == 0)
}
}

0 comments on commit 5b97627

Please sign in to comment.