Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4078

Random test failures after upgrading to 4.0.2

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None
    • None

      We're seeing some strange behaviour after migrating from 3.1.0 and 4.0.2 (with 4.0.0 also exhibiting the same problems)

      From time to time, RSpec tests will fail when #last fails to pick up the last record. Debugging through the tests shows that the record is there on the database, but #last is just not picking it up e.g.

      > Job.all.pluck(:id)
      [BSON::ObjectId('5566010f6865721d58d90200'), BSON::ObjectId('556601106865721d58f60200'), BSON::ObjectId('556601106865721d58130300')]
      > Job.last.id
      BSON::ObjectId('556601106865721d58f60200')
      

      The behaviour is random, in that it will only happen about a third of the time when testing locally - even when the same seed is used for RSpec. Running on CircleCI seems to fail a lot more consistently though.

      We're using the default Mongoid options, since consistency: :strong and safe: true have been deprecated, and it's just the single DB.

      The failing tests are quite straightforward, and take the form:

      let!(:job) {
        Fabricate(
          :job,
          job_items: [ @job_item = Fabricate(:job_item) ]
        )
      }
      
      before do
        @job_item.start_time = new_beginning
        @job_item.save  # this should update the parent job
      end
      
      it "denormalizes the description from job_item" do
        expect(Job.last.description).to include @job_item.ref
      end
      

      Tests aside (which we can definitely improve, and we can fix this particular case by using job.reload in lieu of Job.last), any ideas what might be happening here?

      It's only affecting a small percentage of our tests, but I'm keen to understand whether this is a problem with our test suite, or with the application as a whole...

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            guanglunw guanglunw
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: