-
Notifications
You must be signed in to change notification settings - Fork 145
Serialization traits for data dependencies #1232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
grynspan
wants to merge
17
commits into
main
Choose a base branch
from
jgrynspan/dependency-trait
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f57489d
[WIP] Dependency traits
grynspan 656e479
Merge branch 'main' into jgrynspan/dependency-trait
grynspan 0b080c2
Fixups
grynspan 4b3566a
Disable on Embedded Swift
grynspan 998134b
Typo
grynspan 41da01e
Revise and clean up
grynspan bd1aa4e
Remove factory function that takes a Dependency directly as we don't …
grynspan 4068307
Fix typo
grynspan 6617828
Merge branch 'main' into jgrynspan/dependency-trait
grynspan 5186d20
Use mapValues rather than formal recursion
grynspan 63f76aa
Go back to key paths, make partially available in Embedded
grynspan d76dfe3
Missing Sync import
grynspan 017692b
Merge branch 'main' into jgrynspan/dependency-trait
grynspan 64eb8d4
Move reduce to its own protocol (at least for now)
grynspan fc4724f
Missing #if
grynspan 7beb0e8
Merge branch 'main' into jgrynspan/dependency-trait
grynspan 9f41619
Remove hasFeature(Embedded) checks
grynspan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,61 @@ extension Runner { | |
| } | ||
| } | ||
|
|
||
| /// Post `testStarted` and `testEnded` (or `testSkipped`) events for the test | ||
| /// at the given plan step. | ||
| /// | ||
| /// - Parameters: | ||
| /// - step: The plan step for which events should be posted. | ||
| /// - configuration: The configuration to use for running. | ||
| /// - context: Context for the test run. | ||
| /// - body: A function to execute between the started/ended events. | ||
| /// | ||
| /// - Throws: Whatever is thrown by `body` or while handling any issues | ||
| /// recorded in the process. | ||
| /// | ||
| /// - Returns: Whatever is returned by `body`. | ||
| /// | ||
| /// This function does _not_ post the `planStepStarted` and `planStepEnded` | ||
| /// events. | ||
| private static func _postingTestStartedAndEndedEvents<R>(for step: Plan.Step, configuration: Configuration, context: _Context, _ body: @Sendable () async throws -> R) async throws -> R { | ||
| // Whether to send a `.testEnded` event at the end of running this step. | ||
| // Some steps' actions may not require a final event to be sent — for | ||
| // example, a skip event only sends `.testSkipped`. | ||
| let shouldSendTestEnded: Bool | ||
|
|
||
| // Determine what kind of event to send for this step based on its action. | ||
| switch step.action { | ||
| case .run: | ||
| Event.post(.testStarted, for: (step.test, nil), iteration: context.iteration, configuration: configuration) | ||
| shouldSendTestEnded = true | ||
| case let .skip(skipInfo): | ||
| Event.post(.testSkipped(skipInfo), for: (step.test, nil), iteration: context.iteration, configuration: configuration) | ||
| shouldSendTestEnded = false | ||
| case let .recordIssue(issue): | ||
| // Scope posting the issue recorded event such that issue handling | ||
| // traits have the opportunity to handle it. This ensures that if a test | ||
| // has an issue handling trait _and_ some other trait which caused an | ||
| // issue to be recorded, the issue handling trait can process the issue | ||
| // even though it wasn't recorded by the test function. | ||
| try await Test.withCurrent(step.test) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that this |
||
| try await _applyIssueHandlingTraits(for: step.test) { | ||
| // Don't specify `configuration` when posting this issue so that | ||
| // traits can provide scope and potentially customize the | ||
| // configuration. | ||
| Event.post(.issueRecorded(issue), for: (step.test, nil)) | ||
| } | ||
| } | ||
| shouldSendTestEnded = false | ||
| } | ||
| defer { | ||
| if shouldSendTestEnded { | ||
| Event.post(.testEnded, for: (step.test, nil), iteration: context.iteration, configuration: configuration) | ||
| } | ||
| } | ||
|
|
||
| return try await body() | ||
| } | ||
|
|
||
| /// Run this test. | ||
| /// | ||
| /// - Parameters: | ||
|
|
@@ -216,67 +271,40 @@ extension Runner { | |
| /// | ||
| /// - ``Runner/run()`` | ||
| private static func _runStep(atRootOf stepGraph: Graph<String, Plan.Step?>, context: _Context) async throws { | ||
| // Whether to send a `.testEnded` event at the end of running this step. | ||
| // Some steps' actions may not require a final event to be sent — for | ||
| // example, a skip event only sends `.testSkipped`. | ||
| let shouldSendTestEnded: Bool | ||
| // Exit early if the task has already been cancelled. | ||
| try Task.checkCancellation() | ||
|
|
||
| let configuration = _configuration | ||
|
|
||
| // Determine what action to take for this step. | ||
| if let step = stepGraph.value { | ||
| let configuration = _configuration | ||
| Event.post(.planStepStarted(step), for: (step.test, nil), configuration: configuration) | ||
|
|
||
| // Determine what kind of event to send for this step based on its action. | ||
| switch step.action { | ||
| case .run: | ||
| Event.post(.testStarted, for: (step.test, nil), iteration: context.iteration, configuration: configuration) | ||
| shouldSendTestEnded = true | ||
| case let .skip(skipInfo): | ||
| Event.post(.testSkipped(skipInfo), for: (step.test, nil), iteration: context.iteration, configuration: configuration) | ||
| shouldSendTestEnded = false | ||
| case let .recordIssue(issue): | ||
| // Scope posting the issue recorded event such that issue handling | ||
| // traits have the opportunity to handle it. This ensures that if a test | ||
| // has an issue handling trait _and_ some other trait which caused an | ||
| // issue to be recorded, the issue handling trait can process the issue | ||
| // even though it wasn't recorded by the test function. | ||
| try await Test.withCurrent(step.test) { | ||
| try await _applyIssueHandlingTraits(for: step.test) { | ||
| // Don't specify `configuration` when posting this issue so that | ||
| // traits can provide scope and potentially customize the | ||
| // configuration. | ||
| Event.post(.issueRecorded(issue), for: (step.test, nil)) | ||
| } | ||
| } | ||
| shouldSendTestEnded = false | ||
| } | ||
| } else { | ||
| shouldSendTestEnded = false | ||
| } | ||
| defer { | ||
| if let step = stepGraph.value { | ||
| if shouldSendTestEnded { | ||
| Event.post(.testEnded, for: (step.test, nil), iteration: context.iteration, configuration: configuration) | ||
| } | ||
| defer { | ||
| Event.post(.planStepEnded(step), for: (step.test, nil), configuration: configuration) | ||
| } | ||
| } | ||
|
|
||
| if let step = stepGraph.value, case .run = step.action { | ||
| await Test.withCurrent(step.test) { | ||
| _ = await Issue.withErrorRecording(at: step.test.sourceLocation, configuration: configuration) { | ||
| // Exit early if the task has already been cancelled. | ||
| try Task.checkCancellation() | ||
|
|
||
| try await _applyScopingTraits(for: step.test, testCase: nil) { | ||
| // Run the test function at this step (if one is present.) | ||
| if let testCases = step.test.testCases { | ||
| await _runTestCases(testCases, within: step, context: context) | ||
| switch step.action { | ||
| case .run: | ||
| try await _applyScopingTraits(for: step.test, testCase: nil) { | ||
| try await _postingTestStartedAndEndedEvents(for: step, configuration: configuration, context: context) { | ||
| // Run the test function at this step (if one is present.) | ||
| if let testCases = step.test.testCases { | ||
| await _runTestCases(testCases, within: step, context: context) | ||
| } | ||
|
|
||
| // Run the children of this test (i.e. the tests in this suite.) | ||
| try await _runChildren(of: stepGraph, context: context) | ||
| } | ||
| } | ||
| default: | ||
| // Skipping this step or otherwise not running it. Post appropriate | ||
| // started/ended events for the test and walk any child nodes. | ||
| try await _postingTestStartedAndEndedEvents(for: step, configuration: configuration, context: context) { | ||
| try await _runChildren(of: stepGraph, context: context) | ||
| } | ||
|
|
||
| // Run the children of this test (i.e. the tests in this suite.) | ||
| try await _runChildren(of: stepGraph, context: context) | ||
| } | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is an experimental feature, should the env var name include the word "experimental"?