forked from m-barthelemy/vapor-queues-fluent-driver
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Support MySQL 5.7 #3
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import Logging | |
import FluentSQLiteDriver | ||
|
||
final class QueuesFluentDriverTests: XCTestCase { | ||
func testApplication() throws { | ||
func testApplication() async throws { | ||
let app = Application(.testing) | ||
defer { app.shutdown() } | ||
|
||
|
@@ -19,7 +19,7 @@ final class QueuesFluentDriverTests: XCTestCase { | |
|
||
app.queues.use(.fluent()) | ||
|
||
try app.autoMigrate().wait() | ||
try await app.autoMigrate() | ||
|
||
app.get("send-email") { req in | ||
req.queue.dispatch(Email.self, .init(to: "[email protected]")) | ||
|
@@ -31,19 +31,21 @@ final class QueuesFluentDriverTests: XCTestCase { | |
} | ||
|
||
XCTAssertEqual(email.sent, []) | ||
try app.queues.queue.worker.run().wait() | ||
try await app.queues.queue.worker.run().get() | ||
XCTAssertEqual(email.sent, [.init(to: "[email protected]")]) | ||
|
||
try await app.autoRevert() | ||
} | ||
|
||
func testFailedJobLoss() throws { | ||
func testFailedJobLoss() async throws { | ||
let app = Application(.testing) | ||
defer { app.shutdown() } | ||
|
||
app.databases.use(.sqlite(.memory), as: .sqlite) | ||
app.queues.add(FailingJob()) | ||
app.queues.use(.fluent()) | ||
app.migrations.add(JobModelMigration()) | ||
try app.autoMigrate().wait() | ||
try await app.autoMigrate() | ||
|
||
let jobId = JobIdentifier() | ||
app.get("test") { req in | ||
|
@@ -55,15 +57,17 @@ final class QueuesFluentDriverTests: XCTestCase { | |
XCTAssertEqual(res.status, .ok) | ||
} | ||
|
||
XCTAssertThrowsError(try app.queues.queue.worker.run().wait()) { | ||
await XCTAssertThrowsErrorAsync(try await app.queues.queue.worker.run().get()) { | ||
XCTAssert($0 is FailingJob.Failure) | ||
} | ||
|
||
XCTAssertNotNil(try (app.databases.database(logger: .init(label: ""), on: app.eventLoopGroup.any())! as! any SQLDatabase) | ||
.select().columns("*").from(JobModel.schema).where("id", .equal, jobId.string).first().wait()) | ||
await XCTAssertNotNilAsync(try await (app.databases.database(logger: .init(label: ""), on: app.eventLoopGroup.any())! as! any SQLDatabase) | ||
.select().columns("*").from(JobModel.schema).where("id", .equal, jobId.string).first()) | ||
|
||
try await app.autoRevert() | ||
} | ||
|
||
func testDelayedJobIsRemovedFromProcessingQueue() throws { | ||
func testDelayedJobIsRemovedFromProcessingQueue() async throws { | ||
let app = Application(.testing) | ||
defer { app.shutdown() } | ||
|
||
|
@@ -74,7 +78,7 @@ final class QueuesFluentDriverTests: XCTestCase { | |
app.queues.use(.fluent()) | ||
|
||
app.migrations.add(JobModelMigration()) | ||
try app.autoMigrate().wait() | ||
try await app.autoMigrate() | ||
|
||
let jobId = JobIdentifier() | ||
app.get("delay-job") { req in | ||
|
@@ -88,9 +92,25 @@ final class QueuesFluentDriverTests: XCTestCase { | |
XCTAssertEqual(res.status, .ok) | ||
} | ||
|
||
XCTAssertEqual(try (app.databases.database(logger: .init(label: ""), on: app.eventLoopGroup.any())! as! any SQLDatabase) | ||
await XCTAssertEqualAsync(try await (app.databases.database(logger: .init(label: ""), on: app.eventLoopGroup.any())! as! any SQLDatabase) | ||
.select().columns("*").from(JobModel.schema).where("id", .equal, jobId.string) | ||
.first(decoding: JobModel.self, keyDecodingStrategy: .convertFromSnakeCase).wait()?.state, .pending) | ||
.first(decoding: JobModel.self, keyDecodingStrategy: .convertFromSnakeCase)?.state, .pending) | ||
|
||
try await app.autoRevert() | ||
} | ||
|
||
func testCoverageForFailingQueue() { | ||
let app = Application(.testing) | ||
defer { app.shutdown() } | ||
let queue = FailingQueue( | ||
failure: QueuesFluentError.unsupportedDatabase, | ||
context: .init(queueName: .init(string: ""), configuration: .init(), application: app, logger: .init(label: ""), on: app.eventLoopGroup.any()) | ||
) | ||
XCTAssertThrowsError(try queue.get(.init()).wait()) | ||
XCTAssertThrowsError(try queue.set(.init(), to: JobData(payload: [], maxRetryCount: 0, jobName: "", delayUntil: nil, queuedAt: .init())).wait()) | ||
XCTAssertThrowsError(try queue.clear(.init()).wait()) | ||
XCTAssertThrowsError(try queue.push(.init()).wait()) | ||
XCTAssertThrowsError(try queue.pop().wait()) | ||
} | ||
|
||
override func setUp() { | ||
|
@@ -135,6 +155,47 @@ struct FailingJob: Job { | |
} | ||
} | ||
|
||
func XCTAssertEqualAsync<T>( | ||
_ expression1: @autoclosure () async throws -> T, | ||
_ expression2: @autoclosure () async throws -> T, | ||
_ message: @autoclosure () -> String = "", | ||
file: StaticString = #filePath, line: UInt = #line | ||
) async where T: Equatable { | ||
do { | ||
let expr1 = try await expression1(), expr2 = try await expression2() | ||
return XCTAssertEqual(expr1, expr2, message(), file: file, line: line) | ||
} catch { | ||
return XCTAssertEqual(try { () -> Bool in throw error }(), false, message(), file: file, line: line) | ||
} | ||
} | ||
|
||
func XCTAssertThrowsErrorAsync<T>( | ||
_ expression: @autoclosure () async throws -> T, | ||
_ message: @autoclosure () -> String = "", | ||
file: StaticString = #filePath, line: UInt = #line, | ||
_ callback: (any Error) -> Void = { _ in } | ||
) async { | ||
do { | ||
_ = try await expression() | ||
XCTAssertThrowsError({}(), message(), file: file, line: line, callback) | ||
} catch { | ||
XCTAssertThrowsError(try { throw error }(), message(), file: file, line: line, callback) | ||
} | ||
} | ||
|
||
func XCTAssertNotNilAsync( | ||
_ expression: @autoclosure () async throws -> Any?, | ||
_ message: @autoclosure () -> String = "", | ||
file: StaticString = #filePath, line: UInt = #line | ||
) async { | ||
do { | ||
let result = try await expression() | ||
XCTAssertNotNil(result, message(), file: file, line: line) | ||
} catch { | ||
return XCTAssertNotNil(try { throw error }(), message(), file: file, line: line) | ||
} | ||
} | ||
|
||
func env(_ name: String) -> String? { | ||
return ProcessInfo.processInfo.environment[name] | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.