Skip to content

Commit

Permalink
Fix misuse of EmbeddedEventLoop in tests and disable unfixable test
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynne committed Jan 16, 2025
1 parent 783e930 commit 6378e3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions Tests/FluentKitTests/DummyDatabaseForTestSQLSerializer.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FluentKit
import FluentSQL
import NIOEmbedded
import NIOCore
import SQLKit
import XCTFluent
import NIOConcurrencyHelpers
Expand Down Expand Up @@ -60,7 +60,7 @@ final class DummyDatabaseForTestSQLSerializer: Database, SQLDatabase {
self.context = .init(
configuration: Configuration(),
logger: .init(label: "test"),
eventLoop: EmbeddedEventLoop()
eventLoop: NIOSingletons.posixEventLoopGroup.any()
)
}

Expand All @@ -81,12 +81,14 @@ final class DummyDatabaseForTestSQLSerializer: Database, SQLDatabase {
var sqlSerializer = SQLSerializer(database: self)
query.serialize(to: &sqlSerializer)
self._sqlSerializers.withLockedValue { $0.append(sqlSerializer) }
if !self.fakedRows.isEmpty {
for row in self._fakedRows.withLockedValue({ $0.removeFirst() }) {
return self.eventLoop.submit {
let rows = self._fakedRows.withLockedValue {
$0.isEmpty ? [] : $0.removeFirst()
}
for row in rows {
onRow(row)
}
}
return self.eventLoop.makeSucceededVoidFuture()
}

func transaction<T>(_ closure: @escaping @Sendable (any Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
Expand Down
7 changes: 6 additions & 1 deletion Tests/FluentKitTests/FluentKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ final class FluentKitTests: XCTestCase {
/// Since no part of Fluent or any of its drivers currently relies, or ever will rely, on
/// the format in question, it is desirable to enforce that it should never change, just in
/// case someone actually is relying on it for some hopefully very good reason.
///
/// Update: Ignore all of the above. This test is not reliable due to the instability of serializing
/// dictionaries as strings, and adding sorting changes the output, so the whole point is mooted.
/*
func testAnyModelDescriptionFormatHasNotChanged() throws {
final class Foo: Model, @unchecked Sendable {
static let schema = "foos"
Expand All @@ -47,7 +51,8 @@ final class FluentKitTests: XCTestCase {
XCTAssertEqual(modelOutputDesc, "Foo(output: [num: 42, name: \"Test\", id: \(model.id!)])")
XCTAssertEqual(modelBothDesc, "Foo(output: [num: 42, name: \"Test\", id: \(model.id!)], input: [num: 43])")
}

*/

func testMigrationLogNames() throws {
XCTAssertEqual(MigrationLog.path(for: \.$id), [.id])
XCTAssertEqual(MigrationLog.path(for: \.$name), ["name"])
Expand Down

0 comments on commit 6378e3e

Please sign in to comment.