From a0c7fd21376711abc6427d4aa02ead8c62ceb735 Mon Sep 17 00:00:00 2001 From: Jaume Date: Sun, 3 Nov 2024 23:59:05 +0100 Subject: [PATCH] Improved the queues.md page to add a little extra info about testing (#1008) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added a small brief of the asyncDriver to allow people know you can use that for testing --------- Co-authored-by: Gwynne Raskind --- docs/advanced/queues.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/advanced/queues.md b/docs/advanced/queues.md index 979e3640d..98868d0b0 100644 --- a/docs/advanced/queues.md +++ b/docs/advanced/queues.md @@ -444,3 +444,30 @@ There are a number of third-party packages that use the delegate functionality t - [QueuesDatabaseHooks](https://github.com/vapor-community/queues-database-hooks) - [QueuesDash](https://github.com/gotranseo/queues-dash) + +## Testing + +To avoid synchronization problems and ensure deterministic testing, the Queues package provides an `XCTQueue` library and an `AsyncTestQueuesDriver` driver dedicated to testing which you can use as follows: + +```swift +final class UserCreationServiceTests: XCTestCase { + var app: Application! + + override func setUp() async throws { + self.app = try await Application.make(.testing) + try await configure(app) + + // Override the driver being used for testing + app.queues.use(.asyncTest) + } + + override func tearDown() async throws { + try await self.app.asyncShutdown() + self.app = nil + } +} +``` + +See more details in [Romain Pouclet's blog post](https://romain.codes/2024/10/08/using-and-testing-vapor-queues/). + +