Skip to content

Conversation

rhymes
Copy link
Contributor

@rhymes rhymes commented Apr 16, 2019

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Documentation Update

Description

Running specs in a random order it's a great way to see if there are dependency problems among tests or weird race conditions.

The great thing about this is that by providing the seed with the failing test in a subsequent run it's possible to reproduce the conditions that lead to the tests failing.

I had to make some modifications to some tests to increase robustness (and get rid of the weird behaviors on sequencing and active job related tests)

Added to documentation?

  • docs.dev.to
  • readme
  • no documentation needed

Copy link
Contributor Author

@rhymes rhymes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I "self reviewed" the PR with explanations for each change


# Follow has an after_create callback that creates a channel between the two users,
# so to make sure this test is correct, we delete all channels right after
ChatChannelMembership.delete_all
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I specified in the comment, the Follow model has an after_create callback whose side effect is to create a ChatChannel. The job doesn't create a new channel if there's an existing one. I honestly have no idea what was the combination and the sequence of test leading to no channels so that this one would pass but by removing channels explicitly we can ensure the test always passes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback contains the call to the job perform_later, which won't execute if the queue_adapter is set to test, so the channel was not actually created in the callback and the test passed.
However, I agree that the previous version of the test is not clear regarding the ChatChannel creation, so explicitly deleting makes sense.

@rhymes rhymes changed the title [WIP] Enable random order for specs Enable random order for specs Apr 16, 2019
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Apr 16, 2019
rhymes added 6 commits April 16, 2019 20:57
A few tests are running by chance because the correct combination of variables has been set before execution. Some of these "race conditions" have been surfaced by running in order. The queue adapter value is one of them.

Also using ActiveJob::TestHelper helpers.
Copy link
Contributor

@lightalloy lightalloy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing job. Thanks, @rhymes
I thought about the possible problem with the ActiveJob.queue_adapter inconsistency, but haven't worked on it.

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Apr 17, 2019
@pr-triage pr-triage bot added PR: unreviewed bot applied label for PR's with no review and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Apr 17, 2019
@maestromac maestromac merged commit 7d3fb0c into forem:master Apr 17, 2019
@rhymes rhymes deleted the rhymes/spec-random-order branch April 17, 2019 16:03
coreyja added a commit to coreyja/dev.to that referenced this pull request Apr 20, 2019
* master: (83 commits)
  Update gitdocs (forem#2500)
  Condense 'ask me anything' to 'ama' (forem#2428) [ci skip]
  Add user_signed_in? to cache key for styles (forem#2498)
  Added troubleshooting for byebug without readline issue (forem#2481)
  Fix some frontend linting issues (forem#2495) [ci skip]
  Fix <br/> in footer. (forem#2491)
  Remove extra param and add message for prefill (forem#2487)
  Make Cards Change Dynamically and add Reader/Follower Charts (forem#2488)
  Temporarily comment out random (forem#2486)
  Add nav buttons to pwa desktop (forem#2484)
  Feature/filtered charts (forem#2482)
  Add caching for historical data (forem#2476)
  There are installation sections for other OSes now. (forem#2480)
  Add inbox guidelines to users (forem#2473)
  Release Open Inbox (forem#2468)
  Convert underscores in article slugs properly (forem#2472)
  Update framework defaults to match those in Rails 5.1 (forem#2309)
  Enable random order for specs (forem#2466) [ci skip]
  forem#118 Allow users to embed Medium posts with Liquid Tags (forem#1161)
  Allow API to return top articles (forem#2469)
  ...

# Conflicts:
#	Envfile
#	app/models/user.rb
#	db/schema.rb
@rhymes rhymes mentioned this pull request Jan 19, 2020
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: unreviewed bot applied label for PR's with no review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants