Flaky spec ee/spec/lib/gitlab/audit/events/preloader_spec.rb:37
Job #841987413 failed for 61aec427:
1) Gitlab::Audit::Events::Preloader#find_each yields a list audit events
Failure/Error: expect { |b| preloader.find_each(&b) }.to yield_successive_args(*audit_events)
expected given block to yield successively with arguments, but yielded with unexpected arguments
expected: [#<AuditEvent id: 67, author_id: 2259, entity_id: 2260, entity_type: "User", details: {:change=>"email address", :from=>"admin@gitlab.com", :to=>"maintainer@gitlab.com", :author_name=>"John Doe2569", :target_id=>2260, :target_type=>"User", :target_details=>"John Doe2570", :ip_address=>"127.0.0.1", :entity_path=>"user2345"}, created_at: "2020-11-10 22:10:01", ip_address: #<IPAddr: IPv4:127.0.0.1/255.255.255.255>, author_name: "John Doe2569", entity_path: "user2345", target_details: "John Doe2570", target_type: "User", target_id: 2260>, #<AuditEvent id: 68, author_id: 2261, entity_id: 2262, entity_type: "User", details: {:change=>"email address", :from=>"admin@gitlab.com", :to=>"maintainer@gitlab.com", :author_name=>"John Doe2571", :target_id=>2262, :target_type=>"User", :target_details=>"John Doe2572", :ip_address=>"127.0.0.1", :entity_path=>"user2347"}, created_at: "2020-11-10 22:10:01", ip_address: #<IPAddr: IPv4:127.0.0.1/255.255.255.255>, author_name: "John Doe2571", entity_path: "user2347", target_details: "John Doe2572", target_type: "User", target_id: 2262>]
got: [#<AuditEvent id: 68, author_id: 2261, entity_id: 2262, entity_type: "User", details: {:change=>"email...571", entity_path: "user2347", target_details: "John Doe2572", target_type: "User", target_id: 2262>, #<AuditEvent id: 67, author_id: 2259, entity_id: 2260, entity_type: "User", details: {:change=>"email...569", entity_path: "user2345", target_details: "John Doe2570", target_type: "User", target_id: 2260>]
This looks like it's due to the non-deterministic ordering of records from the DB? It's expecting ID 67 then 68, but got 68 then 67.
EachBatch
should use ordering though created_at
and both have the same value.
Looks like this could be an actual bug that could happen if events have the same date. Couldn't we just sort by :id
like the default does? Otherwise, we could sort by created_at, id
.
cc @tancnle