Skip to content

Commit

Permalink
Improved the queues.md page to add a little extra info about testing (#…
Browse files Browse the repository at this point in the history
…1008)

<!-- πŸš€ Thank you for contributing! -->

<!-- Describe your changes clearly and use examples if possible. -->

* Added a small brief of the asyncDriver to allow people know you can
use that for testing

<!-- When this PR is merged, the title and body will be -->
<!-- used to generate a release automatically. -->

---------

Co-authored-by: Gwynne Raskind <[email protected]>
  • Loading branch information
Dracks and gwynne authored Nov 3, 2024
1 parent 62a7b6c commit a0c7fd2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/advanced/queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/).


0 comments on commit a0c7fd2

Please sign in to comment.