DX-377 Refactor Flakeguard: Separate runner, executor, and parser concerns #1776
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation:
The original
flakeguard/runner/runner.gohad grown significantly, encompassing command execution, complex JSON parsing, error attribution, and result aggregation logic within a single file. This monolithic structure hindered maintainability, testability, and readability. This refactoring addresses these issues by separating concerns into dedicated components.Changes:
Separation of Concerns: The core logic has been divided into distinct responsibilities within the
flakeguard/runnertool directory:runnerpackage (runner.go): Acts as the primary orchestrator. It holds the main configuration, manages the overall workflow (initial runs, reruns), and delegates specific tasks to the executor and parser.executorpackage (executor/executor.go): Defines anExecutorinterface and provides a default implementation (commandExecutor) responsible solely for executinggo testand custom commands, isolatingos/execinteractions and temporary output file handling.parserpackage (parser/parser.go,parser/attribution.go):Parserinterface and provides a default implementation (defaultParserinparser.go).go test -jsonoutput streams, including managing transformations via thego-test-transformlibrary.parser/attribution.go), along with associated regexes and error types.Dependency Injection: Introduced
ExecutorandParserinterfaces. The mainRunnernow accepts these interfaces via theNewRunnerconstructor, enabling easier unit testing by allowing mocks to be injected. Default implementations are used ifnilis passed.Configuration Handling: Introduced
executor.Configandparser.Configstructs to clearly delineate configuration options relevant to each component. The mainRunnerconfigures these based on its own settings.MaxPassRatiowas removed from theRunneras it's considered a reporting/analysis concern.Testing Enhancements:
parserpackage (parser_test.go,attribution_test.go), covering various JSON event scenarios, state transitions, panic/race attribution, subtest handling, run count correction, and output management.runner_integration_test.go) to use the refactoredRunner. Added previously missing scenarios (panics, fail-fast) from the originalrunner_test.goto ensure end-to-end validation against theexample_test_package.example_package_tests) toexample_test_packageto prevent its tests from running during standardflakeguardunit tests, cleaning up test execution logs. Integration tests now explicitly add this tag when invoking theExecutor. This simplifies Flakeguard'sMakefile.Below is a summarization created by an LLM (gpt-4-0125-preview). Be mindful of hallucinations and verify accuracy.
Why
The changes made one at improving the handling of test execution and result parsing for a testing framework. These improvements include better structuring of test runner and parser logic, handling race conditions and panics in tests, and enhancing test result processing with additional attributes like timeout detection and improved error reporting.
What
Runnernow uses anExecutorfor running tests and aParserfor parsing test results, allowing for clearer separation of concerns and easier testing/mocking.executorandparserpackages with interfaces and implementations for executing commands and parsing test results, respectively.TestResultto indicate such issues.testparserpackage and its logic, now integrated into therunnerpackage with improved structure and clarity.This restructuring and enhancement of the test execution and parsing logic aim to provide a more robust, clear, and flexible way of running tests and processing their results, especially in handling complex cases like panics and race conditions.