Repository navigation
tests: find test directories at more than two levels deep - #1915
rootkiller6788 wants to merge 2 commits into
Conversation
list_products only globbed */Gemfile and */*/Gemfile, so samples nested three or more levels in were never picked up at all. That covers the cloud-sql activerecord samples, appengine/flexible and the per-language functions samples: 30 directories with tests that CI silently skipped. */**/Gemfile walks the whole tree and still leaves the top level Gemfile out, same as before.
The three checks in start_cloud_sql_services compared @products against "cloud-sql/mysql" and friends, but the products are the sample dirs, i.e. cloud-sql/mysql/activerecord, so none of them ever matched and no proxy was started for those tests. The SQL Server one also tested for postgres. Match on the directory prefix instead, and test for the sqlserver product in the sqlserver branch.
There was a problem hiding this comment.
Code Review
This pull request refactors the CI script to simplify Gemfile discovery using a recursive glob pattern and introduces a helper method tests_product? to support nested product directories, which also fixes a bug where SQL Server was incorrectly checked as Postgres. The review feedback suggests filtering out third-party dependency and fixture directories (like vendor or .bundle) from the recursive Gemfile search to prevent unexpected test runs, and wrapping @products in Array() within the new helper method to avoid potential NoMethodError crashes if the variable is uninitialized.
| omit_list = ["run/rails/test"] | ||
| @products = [] | ||
| (Dir.glob("*/Gemfile") + Dir.glob("*/*/Gemfile")).each do |gemfile| | ||
| Dir.glob("*/**/Gemfile").each do |gemfile| |
There was a problem hiding this comment.
Using a recursive glob like */**/Gemfile can inadvertently match Gemfiles located inside dependency directories (such as vendor/ or .bundle/) or test fixtures (such as spec/ or test/ subdirectories). This can lead to executing tests on third-party dependencies or fixture code, which may cause unexpected failures or slow down the test suite. Filtering out these directories from the matched paths prevents this issue.
Dir.glob("*/**/Gemfile").each do |gemfile|
next if gemfile.split("/").any? { |part| ["vendor", ".bundle", "node_modules", "test", "spec"].include? part }| # nested underneath a product (for example cloud-sql/mysql/activerecord under | ||
| # cloud-sql/mysql), so match on the directory prefix rather than the exact name. | ||
| def tests_product? name | ||
| @products.any? { |dir| dir == name || dir.start_with?("#{name}/") } |
There was a problem hiding this comment.
If @products is not initialized or is set to nil, calling .any? on it will raise a NoMethodError. Wrapping @products in Array() ensures it is safely coerced to an empty array if it is nil, preventing potential runtime crashes.
Array(@products).any? { |dir| dir == name || dir.start_with?("#{name}/") }
Fixes #1527.
list_products only looked at */Gemfile and //Gemfile, so anything nested deeper never ran at all: the cloud-sql activerecord samples, appengine/flexible and the per-language functions samples. Switched it to */**/Gemfile, which still picks up the first level and still leaves the top level Gemfile out.
I checked that against the current tree rather than eyeballing it: 32 products before, 62 after, none of the old ones dropped, and the top level Gemfile is still excluded.
While I was in there: the three proxy checks in start_cloud_sql_services compare @products against "cloud-sql/mysql" and friends exactly, but the products are the sample directories, so they are really cloud-sql/mysql/activerecord. All three were dead code and no proxy was being started for those tests. The SQL Server branch also tested for postgres. They now match on the directory prefix, and the sqlserver branch tests for the sqlserver product. I bundled that in because turning on the nesting without it would just run the cloud-sql tests with no proxy behind them.
Heads up that this will surface failures in the directories that start running, as you suspected in the issue. If you would rather have those triaged here as well I can keep going, but I did not want to fold unrelated sample fixes into this one.