byroot/frozen_record

Random failures in version 0.26.1

mszyndel opened this issue · 0 comments

When running tests in Bloodhound's main branch I'm seeing random test failures after upgrading to version 0.26.1.

Example test with backtrace

TrackerTest#test_#poll_works_for_Platform_carriers
    Minitest::UnexpectedError: NoMethodError: undefined method `[]' for nil:NilClass

      record = @index[value]
                     ^^^^^^^
    ~/.gem/ruby/3.1.1/gems/frozen_record-0.26.1/lib/frozen_record/index.rb:64 in `lookup`
    ~/.gem/ruby/3.1.1/gems/frozen_record-0.26.1/lib/frozen_record/base.rb:140 in `block in find_by`
    ~/.gem/ruby/3.1.1/gems/frozen_record-0.26.1/lib/frozen_record/base.rb:137 in `each`
    ~/.gem/ruby/3.1.1/gems/frozen_record-0.26.1/lib/frozen_record/base.rb:137 in `find_by`
    ~/.gem/ruby/3.1.1/gems/frozen_record-0.26.1/lib/frozen_record/base.rb:132 in `find`
    app/models/shipify/carrier.rb:76 in `block in providers`
    app/models/shipify/carrier.rb:76 in `map`
    app/models/shipify/carrier.rb:76 in `providers`
    app/models/tracker.rb:79 in `poll`
    ~/.gem/ruby/3.1.1/gems/sorbet-runtime-0.5.10217/lib/types/private/methods/call_validation_2_7.rb:654 in `bind_call`
    ~/.gem/ruby/3.1.1/gems/sorbet-runtime-0.5.10217/lib/types/private/methods/call_validation_2_7.rb:654 in `block in create_validator_method_medium0`
    test/models/tracker_test.rb:118 in `block in <class::TrackerTest>`
  Rerun: dev test test/models/tracker_test.rb:111

Fails in this method

https://github.com/Shopify/bloodhound/blob/main/app/models/shipify/carrier.rb#L73-L77

    def providers
      return [] if provider_ids.nil?

      provider_ids.map { |id| ShipifyProvider.find(id) }
    end

Can't replicate it in CI so I believe it has to do with eager loading, since it's disabled in development and test when in CI.