Skip to content

Commit

Permalink
Fix error handling in tests, remove redundant test
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynne committed Mar 24, 2024
1 parent ca7c8b1 commit 2b9e6e6
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions Tests/PostgresKitTests/PostgresKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import Foundation
final class PostgresKitTests: XCTestCase {
func testSQLKitBenchmark() throws {
let conn = try PostgresConnection.test(on: self.eventLoop).wait()
defer { try! conn.close().wait() }
defer { try? conn.close().wait() }
let benchmark = SQLBenchmarker(on: conn.sql())
try benchmark.run()
do {
try benchmark.run()
} catch {
XCTFail("Caught error: \(String(reflecting: error))")
}
}

func testPerformance() throws {
Expand Down Expand Up @@ -56,37 +60,41 @@ final class PostgresKitTests: XCTestCase {

let db = conn.sql()

try db.raw("DROP TABLE IF EXISTS \(ident: "foos")").run().wait()
try db.raw("""
CREATE TABLE \(ident: "foos") (
\(ident: "id") TEXT PRIMARY KEY,
\(ident: "description") TEXT,
\(ident: "latitude") DOUBLE PRECISION,
\(ident: "longitude") DOUBLE PRECISION,
\(ident: "created_by") TEXT,
\(ident: "created_at") TIMESTAMPTZ,
\(ident: "modified_by") TEXT,
\(ident: "modified_at") TIMESTAMPTZ
)
""").run().wait()
defer {
try? db.raw("DROP TABLE IF EXISTS \(ident: "foos")").run().wait()
}

for i in 0..<5_000 {
let zipcode = Foo(
id: UUID().uuidString,
description: "test \(i)",
latitude: Double.random(in: 0...100),
longitude: Double.random(in: 0...100),
created_by: "test",
created_at: Date(),
modified_by: "test",
modified_at: Date()
do {
try db.raw("DROP TABLE IF EXISTS \(ident: "foos")").run().wait()
try db.raw("""
CREATE TABLE \(ident: "foos") (
\(ident: "id") TEXT PRIMARY KEY,
\(ident: "description") TEXT,
\(ident: "latitude") DOUBLE PRECISION,
\(ident: "longitude") DOUBLE PRECISION,
\(ident: "created_by") TEXT,
\(ident: "created_at") TIMESTAMPTZ,
\(ident: "modified_by") TEXT,
\(ident: "modified_at") TIMESTAMPTZ
)
try db.insert(into: "foos")
.model(zipcode)
.run().wait()
""").run().wait()
defer {
try? db.raw("DROP TABLE IF EXISTS \(ident: "foos")").run().wait()
}

for i in 0..<5_000 {
let zipcode = Foo(
id: UUID().uuidString,
description: "test \(i)",
latitude: Double.random(in: 0...100),
longitude: Double.random(in: 0...100),
created_by: "test",
created_at: Date(),
modified_by: "test",
modified_at: Date()
)
try db.insert(into: "foos")
.model(zipcode)
.run().wait()
}
} catch {
XCTFail("Caught error: \(String(reflecting: error))")
}
}

Expand Down Expand Up @@ -149,12 +157,6 @@ final class PostgresKitTests: XCTestCase {
XCTAssertEqual(rows.first?.first?.dataType, Bar.psqlArrayType)
XCTAssertEqual(try rows.first?.first?.decode([Bar].self), [Bar]())
}

func testEnum() throws {
let connection = try PostgresConnection.test(on: self.eventLoop).wait()
defer { try! connection.close().wait() }
try SQLBenchmarker(on: connection.sql()).testEnum()
}

/// Tests dealing with encoding of values whose `encode(to:)` implementation calls one of the `superEncoder()`
/// methods (most notably the implementation of `Codable` for Fluent's `Fields`, which we can't directly test
Expand Down

0 comments on commit 2b9e6e6

Please sign in to comment.