Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test for Swift 6 Linux Date Precision Bug #222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Tests/FluentPostgresDriverTests/FluentPostgresDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,47 @@ final class FluentPostgresDriverTests: XCTestCase {
try await db.schema(Seq.schema).delete()
}

func testSwift6DatePrecisionBug() async throws {
final class Event: Model, @unchecked Sendable {
static let schema = "orgs"

@ID(custom: "id", generatedBy: .database) var id: Int?
@Field(key: "date") var date: Date

init() {}
}

struct CreateEvent: AsyncMigration {
func prepare(on database: any Database) async throws {
try await database.schema("orgs")
.field("id", .int, .identifier(auto: true))
.field("date", .datetime, .required)
.create()
}

func revert(on database: any Database) async throws {
try await database.schema("orgs").delete()
}
}

try await CreateEvent().prepare(on: self.db)
do {
let date = Date()
let new = Event()
XCTAssertEqual(date.timeIntervalSince1970, date.timeIntervalSince1970)
new.date = date
XCTAssertEqual(new.date.timeIntervalSince1970, date.timeIntervalSince1970)
try await new.save(on: self.db)
XCTAssertEqual(new.date.timeIntervalSince1970, date.timeIntervalSince1970)
let fetched = try await Event.query(on: self.db).first()!
XCTAssertEqual(fetched.date.timeIntervalSince1970, date.timeIntervalSince1970)
} catch {
try? await CreateEvent().revert(on: self.db)
throw error
}
try await CreateEvent().revert(on: self.db)
}


var benchmarker: FluentBenchmarker { .init(databases: self.dbs) }
var eventLoopGroup: any EventLoopGroup { MultiThreadedEventLoopGroup.singleton }
Expand Down
Loading