Skip to content

test preload passing an array #23402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Mar 31, 2025

No description provided.

@kbrock kbrock added the test label Mar 31, 2025
@kbrock kbrock requested a review from Fryguy as a code owner March 31, 2025 17:22
host = FactoryBot.create(:host_vmware) # infra
FactoryBot.create_list(:vm, 2, :ext_management_system => FactoryBot.create(:ems_infra), :host => host)
emses = ExtManagementSystem.all
expect { preload(emses, [:vms, :host]) }.to make_database_queries(:count => 2)
Copy link
Member

@jrafanie jrafanie Mar 31, 2025

Choose a reason for hiding this comment

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

hosts? plural?

  1) MiqPreloader.preload preloads association array
     Failure/Error: ActiveRecord::Associations::Preloader.new(:records => Array(records), :associations => associations, :scope => preload_scope).call

     ActiveRecord::AssociationNotFoundError:
       Association named 'host' was not found on ManageIQ::Providers::Vmware::InfraManager; perhaps you misspelled it?
     # ./lib/miq_preloader.rb:25:in `preload'
     # ./spec/lib/miq_preloader_spec.rb:115:in `preload'
     # ./spec/lib/miq_preloader_spec.rb:108:in `block (4 levels) in <top (required)>'
     # ./spec/lib/miq_preloader_spec.rb:108:in `block (3 levels) in <top (required)>'

Copy link
Member Author

Choose a reason for hiding this comment

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

ugh. thnx

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

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

See test failure above

@kbrock kbrock force-pushed the test_preload_array branch from 6c1571b to fd8a72f Compare April 1, 2025 01:04
@kbrock
Copy link
Member Author

kbrock commented Apr 1, 2025

ok, so this is failing on trying to preload the host in the ems.

To me it looks like it is flattening the preload hash into just an array.
From what I can tell, this is correct behavior.

My concern:
I found code that I think expects different behavior:

manageiq $ ag 'preload\([^)]*=>'

app/models/storage.rb
692:        MiqPreloader.preload(self, :vms => :storage_files_files)

app/models/manageiq/providers/cloud_manager/metrics_capture.rb
6:    MiqPreloader.preload([ems], :vms => [{:availability_zone => :tags}, :ext_management_system])

app/models/manageiq/providers/container_manager/metrics_capture.rb
5:    MiqPreloader.preload([ems], :container_images => :tags, :container_nodes => :tags, :container_groups => [:tags, {:containers => :tags}])

@kbrock kbrock force-pushed the test_preload_array branch from fd8a72f to 490d781 Compare April 1, 2025 01:14
@kbrock kbrock force-pushed the test_preload_array branch from 490d781 to 65dc5f8 Compare April 1, 2025 16:57
@kbrock
Copy link
Member Author

kbrock commented Apr 1, 2025

@jrafanie update:

  • fixed association to update with hash and array

update:

  • fixed test to compare correct values

This should be good to go

@jrafanie
Copy link
Member

jrafanie commented Apr 1, 2025

My concern:
I found code that I think expects different behavior:

sorry, what was the resolution of this @kbrock ?

@kbrock
Copy link
Member Author

kbrock commented Apr 15, 2025

@jrafanie all set. it successfully handles hash and array - it was a bad test/misunderstood failure.

This is validating our expectations successfully

@jrafanie jrafanie merged commit 01ba1e3 into ManageIQ:master Apr 21, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants