Skip to content

Commit 77b23e8

Browse files
committed
Cleanup, load dotfiles only once
1 parent 6f547b0 commit 77b23e8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Tests/AppTests/Helpers/DatabasePool.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ actor DatabasePool {
2727
struct Database: Hashable {
2828
var id: DatabaseID
2929
var port: Int
30+
31+
var connectionDetails: ConnectionDetails {
32+
.init(port: port)
33+
}
3034
}
3135

3236
static let shared = DatabasePool(maxCount: 8)
@@ -40,6 +44,7 @@ actor DatabasePool {
4044
var availableDatabases: Set<Database> = .init()
4145

4246
func setUp() async throws {
47+
await DotEnvFile.load(for: .testing, fileio: .init(threadPool: .singleton))
4348
try await withThrowingTaskGroup(of: Database.self) { group in
4449
for _ in (0..<maxCount) {
4550
group.addTask {
@@ -120,7 +125,7 @@ extension DatabasePool.Database {
120125
var username: String
121126
var password: String
122127

123-
init(with environment: Environment, port: Int) {
128+
init(port: Int) {
124129
// Ensure DATABASE_HOST is from a restricted set db hostnames and nothing else.
125130
// This is safeguard against accidental inheritance of setup in QueryPerformanceTests
126131
// and to ensure the database resetting cannot impact any other network hosts.
@@ -134,8 +139,7 @@ extension DatabasePool.Database {
134139
}
135140

136141
func setup(for environment: Environment) async throws {
137-
await DotEnvFile.load(for: environment, fileio: .init(threadPool: .singleton))
138-
let details = ConnectionDetails(with: environment, port: port)
142+
let details = ConnectionDetails(port: port)
139143

140144
// Create initial db snapshot
141145
try await createSchema(environment, details: details)

Tests/AppTests/Helpers/TestSupport.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ func withApp(
3030
}
3131

3232
try await DatabasePool.shared.withDatabase { database in
33-
#warning("make this a method on Database?")
34-
let details = DatabasePool.Database.ConnectionDetails(with: environment, port: database.port)
35-
try await database.restoreSnapshot(details: details)
33+
try await database.restoreSnapshot(details: database.connectionDetails)
3634
let app = try await Application.make(environment)
3735
try await configure(app, databasePort: database.port)
3836

0 commit comments

Comments
 (0)