Skip to content

tests: find test directories at more than two levels deep - #1915

Draft
rootkiller6788 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
rootkiller6788:fix-kokoro-nested-test-discovery
Draft

rootkiller6788 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
rootkiller6788:fix-kokoro-nested-test-discovery

Conversation

@rootkiller6788

Copy link
Copy Markdown

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.

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.
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Nov 28, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread .toys/kokoro-ci.rb
omit_list = ["run/rails/test"]
@products = []
(Dir.glob("*/Gemfile") + Dir.glob("*/*/Gemfile")).each do |gemfile|
Dir.glob("*/**/Gemfile").each do |gemfile|

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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 }

Comment thread .toys/kokoro-ci.rb
# 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}/") }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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}/") }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kokoro: not all tests being run

1 participant