• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

trotzig / diffux / 91 / 2
99%
master: 99%

Build:
DEFAULT BRANCH: master
Ran 06 Feb 2014 01:05AM UTC
Files 17
Run time –
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

06 Feb 2014 01:02AM UTC coverage: 98.008% (+0.02%) from 97.992%
2.1.0

push

travis-ci

lencioni
Use after_commit on Snapshot to set up SnapshotWorker

As @trotzig pointed out[1], rescuing ActiveRecord::RecordNotFound in the
SnapshotWorker is potentially not safe due to a risk for a race
condition. If the job starts right at the same time as the Snapshot is
being commited to the database, the worker might start before it is
created causing the ActiveRecord::RecordNotFound exception to be raised.
Under normal circumstances, Sidekiq will simply re-enqueue the job and
it will try it again likely after the record has been created.

To prevent this, I am moving the enqueueing of the SnapshotWorker from
SnapshotsController to an after_commit on create method on the Snapshot
model. This has the additional benefit of ensuring that a Snapshot
worker is spawned every time a new Snapshot is created, no matter where
it is created. Also, this allows us to remove the arbitrary 2 second
delay in wiring up the worker, which was added to prevent this type of
race condition.

To get this to work correctly with our tests, I needed to do some
trickery. By default, queries are run inside of transactions in our
tests because we have set `use_transactional_fixtures` to `true` in our
RSpec configuration. However, that means that the `after_commit`
callback will not be executed because the data is never actually
committed when this option is on. To allow this to happen, we need to
turn off this option. Instead of doing this globally, I decided that it
would be best to do this just for the tests that require `after_commit`
to actually run. So, borrowing from a gist I found[2], I added a tag
that allows us to tag examples that need this behavior. Now, for
examples that are tagged with `:uses_after_commit`, RSpec will turn off
the transactional fixtures, which will actually commit to the database,
which will cause the `after_commit` code to execute. To keep the
database clean, I brought in the database_cleaner gem.

[1]: https://github.com/trotzig/diffux/commit/3a14ea2c6#commitcomment-5289411
[2]: https://gist.github.com/maxim/2902072

Change-Id: Ie67a5b913

246 of 251 relevant lines covered (98.01%)

58.76 hits per line

Source Files on job 91.2 (2.1.0)
  • Tree
  • List 0
  • Changed 7
  • Source Changed 2
  • Coverage Changed 7
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 91
  • Travis Job 91.2
  • 7ffe2c35 on github
  • Prev Job for 2.1.0 on master (#90.2)
  • Next Job for 2.1.0 on master (#92.2)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc