Conversation
| Name: "location-prefix", | ||
| Category: "TEST RUNNER", | ||
| Usage: "Prefix to prepend to test file paths when requesting a test plan, used to match the test files reported by the test collector", | ||
| Sources: cli.EnvVars("BUILDKITE_TEST_ENGINE_LOCATION_PREFIX", "BUILDKITE_ANALYTICS_LOCATION_PREFIX"), |
There was a problem hiding this comment.
Using only BUILDKITE_ANALYTICS_LOCATION_PREFIX is inconsistent with other environment variables namespace in bktec. The location prefix can be configured for the test collector without that environment variable (e.g via collector config object) so it might not be present. Supporting BUILDKITE_TEST_ENGINE_LOCATION_PREFIX will make it consistent.
There was a problem hiding this comment.
Should be encouraging the deprecation of BUILDKITE_ANALYTICS_LOCATION_PREFIXin favour of BUILDKITE_TEST_ENGINE_LOCATION_PREFIX in our collectors?
gchan
left a comment
There was a problem hiding this comment.
This looks good and I've left some comments and questions.
While we did planned to use locationPrefix to handle both ./ and /path/to/dir cases, I wonder if we are overloading it given that I noticed we treat both cases differently (one we trim, and the other we don't).
I wonder if we can make it clearer how we are handling location prefixes and why (with examples) because I'm afraid that this knowledge might slowly disappear.
| TagFilters string | ||
| TestRunner string | ||
|
|
||
| locationPrefix string |
There was a problem hiding this comment.
Nipick - should this attribute be capitalised?
Is there a reason to not export this field?
There was a problem hiding this comment.
Some test runner (e.g. rspec) will set a default value to this attribute, so the value should be accessed from the runner interface. In golang, you can't have a static attribute on an interface and it should be a getter function. The options are:
- have a public attribute
LocationPrefixand create a getterGetLocationPrefix()on the runner interface - have a private attribute
locationPrefixand create a getterLocationPrefix()on the runner interface
I chose 2 as it is recommended by golang https://go.dev/doc/effective_go#Getters, and since other package should not access the raw locationPrefix directly (without default value that runner set)
internal/command/request_param.go
Outdated
| filteredFilesPath = append(filteredFilesPath, file.Path) | ||
| // File paths sent to the API for filtering tests include the location prefix to match Test Engine records. | ||
| // However, the test runner expects file paths without the prefix, so we need to remove it before running the tests. | ||
| trimmedPath, err := trimFilePathPrefix(file.Path, prefix) |
There was a problem hiding this comment.
To clarify what's going on in this class:
- createRequestParam prepends the prefixes
- splitAllFiles calls
runner.GetExampleswith the prefixes and doesn't remove the prefixes from the examples it returns - filterAndSplitFiles trims the prefixes (unless it is
./) and then callsrunner.GetExampleswith the prefixes removed. It appears the examples returned has it's prefixes removed?
What's the reason behind this difference it handling?
| } | ||
| } | ||
|
|
||
| func TestCreateRequestParams_WithLocationPrefix(t *testing.T) { |
There was a problem hiding this comment.
This test and the next one are the new tests, the other tests have been moved from run_test.go
| { | ||
| Identifier: "./testdata/rspec/spec/fruits/banana_spec.rb[1:1]", | ||
| Name: "is yellow", | ||
| Path: "./testdata/rspec/spec/fruits/banana_spec.rb[1:1]", |
There was a problem hiding this comment.
What's the reason behind the different treatment of examples vs files?
There was a problem hiding this comment.
We don't identify examples by filename, but with name and scope. So bktec doesn't need to prepend the fixes when requesting the test plan. Do you think we should add the prefix as well for consistency, even if we don't need it?
There was a problem hiding this comment.
Yep, for consistency and to reduce confusion, I think we should!
There was a problem hiding this comment.
I handle the examples' Path, but I'm leaving Identifier as is because Identifier might not be a path for other runners.
There was a problem hiding this comment.
Do we want to add a brief comment in getExamplesWithPrefix to explain the divergence for future travellers?
| Name: "location-prefix", | ||
| Category: "TEST RUNNER", | ||
| Usage: "Prefix to prepend to test file paths when requesting a test plan, used to match the test files reported by the test collector", | ||
| Sources: cli.EnvVars("BUILDKITE_TEST_ENGINE_LOCATION_PREFIX", "BUILDKITE_ANALYTICS_LOCATION_PREFIX"), |
There was a problem hiding this comment.
Should be encouraging the deprecation of BUILDKITE_ANALYTICS_LOCATION_PREFIXin favour of BUILDKITE_TEST_ENGINE_LOCATION_PREFIX in our collectors?
| for _, c := range cases { | ||
| got := NewJest(c.input) | ||
| if diff := cmp.Diff(got.RunnerConfig, c.want); diff != "" { | ||
| if diff := cmp.Diff(got.RunnerConfig, c.want, cmp.AllowUnexported(RunnerConfig{})); diff != "" { |
There was a problem hiding this comment.
My understanding is that this is so we can compare for the unexported field locationPrefix.
There was a problem hiding this comment.
Nice sorting of the attributes.
Nitpick - I wonder if it makes sense to continue grouping common attributes together similar to how we display them in the cli --help command?
gchan
left a comment
There was a problem hiding this comment.
Giving this an early approval given my major questions about consistency has (or will) been handled.
8c27f10 to
a1721ea
Compare
| } | ||
| } | ||
|
|
||
| func getExamplesWithPrefix(filePaths []string, runner TestRunner) ([]plan.TestCase, error) { |
There was a problem hiding this comment.
this function is called by filterAndSplitFiles and splitAllFiles since we need to handle it the same way.
gchan
left a comment
There was a problem hiding this comment.
Nice work! Thanks for getting rid of the special ./ case. ![]()
When using
bktecwith a custom runner for minitest, test plans weren't being optimally bin-packed. All test durations were coming back as1000(the default). The root cause is that the minitest collector uploads file paths with a./prefix (e.g.,./spec/models/user_spec.rb), butbktecsends paths without it (e.g.,spec/models/user_spec.rb). Since the paths don't match, the API can't look up actual durations.This is the same class of problem that affects customers using the JS collector with a custom prefix (e.g.,
frontend/in a monorepo). The collector knows about the prefix, butbktecdoesn't.I've added a
--location-prefixflag (sourced from bothBUILDKITE_TEST_ENGINE_LOCATION_PREFIXandBUILDKITE_ANALYTICS_LOCATION_PREFIX) that prepends a prefix to file paths when requesting a test plan from the API, and strips it before passing paths to the test runner for execution.Usage
Or via environment variable: