2026-07-11 09:15:58 +00:00
|
|
|
import FluentKit
|
|
|
|
|
import HummingbirdFluent
|
|
|
|
|
import Logging
|
|
|
|
|
import Testing
|
|
|
|
|
|
|
|
|
|
@testable import Persistence
|
|
|
|
|
|
2026-07-30 06:33:57 +00:00
|
|
|
@Suite(
|
|
|
|
|
"Probe method",
|
|
|
|
|
.tags(.method)
|
|
|
|
|
)
|
2026-07-11 09:15:58 +00:00
|
|
|
struct ProbeTests {
|
|
|
|
|
|
|
|
|
|
// MARK: Methods tests
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
func `reports a reachable database`() async throws {
|
2026-08-04 16:59:43 +02:00
|
|
|
let service = try Service(
|
2026-07-11 09:15:58 +00:00
|
|
|
driver: .inMemory,
|
|
|
|
|
logger: Logger(label: "test")
|
|
|
|
|
)
|
2026-08-04 16:59:43 +02:00
|
|
|
let fluent = service()
|
2026-07-11 09:15:58 +00:00
|
|
|
let probe = Probe(fluent: fluent)
|
|
|
|
|
|
|
|
|
|
let isReachable = await probe()
|
|
|
|
|
|
|
|
|
|
try await fluent.shutdown()
|
|
|
|
|
|
|
|
|
|
#expect(isReachable)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
func `reports an unreachable database`() async throws {
|
|
|
|
|
// Port 1 on the loopback interface has nothing listening, so the connection is refused
|
|
|
|
|
// immediately instead of timing out.
|
2026-08-04 16:59:43 +02:00
|
|
|
let service = try Service(
|
2026-08-04 15:48:13 +02:00
|
|
|
driver: .postgres(
|
2026-07-11 09:15:58 +00:00
|
|
|
.init(
|
|
|
|
|
host: "127.0.0.1",
|
|
|
|
|
port: 1,
|
|
|
|
|
name: "unreachable",
|
|
|
|
|
username: "nobody",
|
|
|
|
|
password: "nothing",
|
|
|
|
|
tls: .off,
|
|
|
|
|
maxConnectionsPerEventLoop: 1
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
logger: Logger(label: "test")
|
|
|
|
|
)
|
2026-08-04 16:59:43 +02:00
|
|
|
let fluent = service()
|
2026-07-11 09:15:58 +00:00
|
|
|
let probe = Probe(fluent: fluent)
|
|
|
|
|
|
|
|
|
|
let isReachable = await probe()
|
|
|
|
|
|
|
|
|
|
try await fluent.shutdown()
|
|
|
|
|
|
|
|
|
|
#expect(!isReachable)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
func `reports a default database that is not an SQL database`() async throws {
|
|
|
|
|
let fluent = Fluent(logger: Logger(label: "test"))
|
|
|
|
|
|
|
|
|
|
fluent.databases.use(
|
|
|
|
|
.init(make: { NotSQLConfiguration() }),
|
|
|
|
|
as: .init(string: "not-sql"),
|
|
|
|
|
isDefault: true
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
let probe = Probe(fluent: fluent)
|
|
|
|
|
|
|
|
|
|
let isReachable = await probe()
|
|
|
|
|
|
|
|
|
|
try await fluent.shutdown()
|
|
|
|
|
|
|
|
|
|
#expect(!isReachable)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|