Repository navigation
Add Queue.fake() for tests - #15
Merged
Merged
Conversation
Contributor
Author
Bot reviewVerdict: OK. Nothing is blocking. What I checked:
Nits (no fix needed):
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Tests had no way to fake the queue. They had to use the
syncdriver, which really runs every job. So a test could not check "this job was dispatched" without running it.Fix
Queue.fake()returns aQueueFake. While it is on,Queue.dispatch()(andjob.dispatch()) keeps the job in a list. It does not run or save it. It needs noQueue.configure().assertPushed<T>([test]),assertPushedTimes<T>(n),assertNotPushed<T>(),assertNothingPushed(). A failed check throws anAssertionErrorthat says what was pushed.pushed(eachPushedJobhasjob,queueanddelay),jobsOf<T>(),pushedOf<T>().clear()forgets them.Queue.restore()stops the fake. This matchesMail.fake()/Mail.restore()of dox_mailer.Mail.queue()andMail.later()go throughQueue.dispatch(), so the fake catches them too.dispatchSync()is not faked. It still runs the job, like before.No breaking change. No version bump. Changelog is under Unreleased. README and docs/queue.md have a new part in Testing.
Tests
test/queue_fake_test.dart: each assert, with its failure message, queue name and delay,dispatchSync,Mail.queue()/Mail.later(), andrestore.dart analyze: no issues.dart test: all passed (97 passed, 90 skipped stores).