Avoid needing a shell to support Distroless Container Images (in most cases)#299
Avoid needing a shell to support Distroless Container Images (in most cases)#299
Conversation
| it 'returns test example paths for slow test files' do | ||
| logger = instance_double(Logger) | ||
| allow(KnapsackPro).to receive(:logger).and_return(logger) | ||
| allow(logger).to receive(:info) | ||
|
|
||
| cmd = 'bundle exec rake knapsack_pro:rspec_test_example_detector' | ||
| env = { 'RACK_ENV' => 'test', 'RAILS_ENV' => 'test' } | ||
| expect(Kernel).to receive(:system).with(env, cmd).and_return(true) | ||
|
|
||
| rspec_test_example_detector = instance_double(KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector) | ||
| expect(KnapsackPro::TestCaseDetectors::RSpecTestExampleDetector).to receive(:new).and_return(rspec_test_example_detector) | ||
|
|
||
| test_file_example_paths = double | ||
| expect(rspec_test_example_detector).to receive(:test_file_example_paths).and_return(test_file_example_paths) | ||
|
|
||
| expect(subject).to eq test_file_example_paths | ||
|
|
||
| cmd = 'RACK_ENV=test RAILS_ENV=test bundle exec rake knapsack_pro:rspec_test_example_detector' | ||
| expect(Kernel).to receive(:system).with(cmd).and_return(cmd_result) | ||
| expect(logger).to have_received(:info).with("Generating RSpec test examples JSON report for slow test files to prepare it to be split by test examples (by individual test cases). Thanks to that, a single slow test file can be split across parallel CI nodes. Analyzing 5 slow test files.") | ||
| end |
There was a problem hiding this comment.
Note for the future:
These tests need too many doubles so it's pretty fragile.
If we want to test behavior with so many side effects, let's use an integration test. If we want to test specifics (Kernel receives some arguments), let's create a separate method and unit test just that (without stubbing so many things).
I would have picked the latter in this case.
Co-authored-by: Riccardo <riccardo.odone@gmail.com>
This PR reverts changes from 8.2.0 version that have been introduced in: * #299 to address the issue reported in: * #301 But we keep some code simplification: * Keep Kernel.exec for Spinach to avoid catching the exit code * Keep: fd13e84 - we removed the unneeded `EXTRA_TEST_FILES_DELAY` env var in CircleCI yml that was accidentally added some time ago.
| namespace :queue do | ||
| task :rspec, [:rspec_args] do |_, args| | ||
| Kernel.exec("RAILS_ENV=test RACK_ENV=test #{$PROGRAM_NAME} 'knapsack_pro:queue:rspec_go[#{args[:rspec_args]}]'") | ||
| Kernel.exec({ 'RAILS_ENV' => 'test', 'RACK_ENV' => 'test' }, $PROGRAM_NAME, "knapsack_pro:queue:rspec_go[#{args[:rspec_args]}]") |
There was a problem hiding this comment.
If you are referring to the missing ' in 'knapsack_pro:queue:rspec_go[#{args[:rspec_args]}]', that was left out intentionally.
Previously, the quotes were used to ensure the arguments were parsed correctly. However, since we now pass "knapsack_pro:queue:rspec_go[#{args[:rspec_args]}]" as a positional argument, they are no longer necessary. Argument parsing still works, for example, running: bundle exec rake "knapsack_pro:queue:rspec[--format d --no-color]" will use the documentation format and disable color in the output.
There was a problem hiding this comment.
Hmm, yea it should be getting invoked right. I'd love to have repro steps for #301, it's frustrating attempting to figure out what's happening from very little info :(
There was a problem hiding this comment.
I'd love to have repro steps for #301, it's frustrating attempting to figure out what's happening from very little info :(
I know the struggle. Reproducing unexpected edge cases without enough information can be really tricky.
Story
https://trello.com/c/NmNCGtoE
Related
Based on PR:
Description
Avoid needing a shell to support Distroless Container Images (in most cases).
If you pass an environment variable to
KNAPSACK_PRO_RSPEC_TEST_EXAMPLE_DETECTOR_PREFIXlike"MY_CUSTOM_VARIABLE=value bundle exec"then shell is required when running an RSpec dry run task to determine test examples for slow test files. This will not work in Distroless Container Image.Checklist reminder
UNRELEASEDsection of theCHANGELOG.md, including the needed bump (ie, patch, minor, major)lib/knapsack_pro/pure/queue/rspec_pure.rbcontains pure functions that are unit tested.lib/knapsack_pro/extensions/rspec_extension.rbencapsulates calls to RSpec internals and is integration and e2e tested.lib/knapsack_pro/runners/queue/rspec_runner.rbinvokes the pure code and the extension to produce side effects, which are integration and e2e tested.