-
Notifications
You must be signed in to change notification settings - Fork 0
SPI & Codecov #10
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
SPI & Codecov #10
Changes from all commits
22e35ce
060eb73
8847ee8
714abdc
69cd43d
cc473a6
998af0b
d49c156
e48a57c
d844249
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| version: 1 | ||
| builder: | ||
| configs: | ||
| - documentation_targets: | ||
| - Principle | ||
| - PrincipleConcurrency | ||
| - PrincipleCollections |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SingleUseTransferTests.swift | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Principle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Created by Kamil Strzelecki on 28/04/2025. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Copyright © 2025 Kamil Strzelecki. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @testable import PrincipleConcurrency | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Synchronization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Testing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal struct SingleUseTransferTests { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func testFinalize() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mutex = Mutex(NonSendable()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let instance = NonSendable() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var transfer = SingleUseTransfer(instance) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mutex.withLock { protected in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected = transfer.finalize() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func testTake() async { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let instance = NonSendable() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var transfer = SingleUseTransfer(instance) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await withTaskGroup { group in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var transfer = transfer.take() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| group.addTask { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _ = transfer.finalize() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await group.waitForAll() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+26
to
+38
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. 🛠️ Refactor suggestion Enhance concurrent testing scenario. The current test doesn't effectively test concurrent behavior with just one task. Consider adding multiple concurrent tasks that attempt to finalize the same transfer and verify that only one succeeds. @Test
func testTake() async {
let instance = NonSendable()
var transfer = SingleUseTransfer(instance)
+ // Use an actor to safely track successful finalizations
+ actor FinalizationTracker {
+ var successCount = 0
+ func incrementSuccess() { successCount += 1 }
+ func getSuccessCount() -> Int { successCount }
+ }
+
+ let tracker = FinalizationTracker()
+
await withTaskGroup { group in
var transfer = transfer.take()
- group.addTask {
- _ = transfer.finalize()
- }
+
+ // Add multiple tasks attempting to finalize the same transfer
+ for _ in 1...10 {
+ group.addTask {
+ do {
+ _ = transfer.finalize()
+ await tracker.incrementSuccess()
+ } catch {
+ // Precondition failure would terminate the process in real code
+ // In a test environment, we'd catch the resulting error
+ }
+ }
+ }
await group.waitForAll()
}
+
+ // Verify only one task successfully finalized the transfer
+ let successCount = await tracker.getSuccessCount()
+ XCTAssertEqual(successCount, 1, "Only one task should successfully finalize the transfer")
}Note: This implementation assumes precondition failures can be caught as errors for testing purposes, which may not be the case in your environment. You might need to adapt this approach based on your testing infrastructure. 📝 Committable suggestion
Suggested change
Owner
Author
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. This is intentional - 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. @NSFatalError I understand now, thank you for the clarification. You're right that the test is specifically checking if the (_/) ✏️ Learnings added
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extension SingleUseTransferTests { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private final class NonSendable {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
💡 Verification agent
🧩 Analysis chain
Verify generation of
.profdatabefore exportThe
llvm-cov exportstep references.build/debug/codecov/default.profdata, but it’s unclear ifswift test --enable-code-coverageautomatically merges raw profiles into a.profdatafile. Confirm that the.profdataexists or insert anllvm-profdata mergestep if necessary.Run this script to check and merge profiles if needed:
🏁 Script executed:
Length of output: 364
Add an explicit
llvm-profdatamerge step before exporting coverageswift test --enable-code-coverageproduces.profrawfiles but does not automatically merge them into a.profdata. Without that merge, thexcrun llvm-cov export … -instr-profile .build/debug/codecov/default.profdatastep will fail.Suggested patch in .github/workflows/pull-request.yml (after the
swift test …line and before findingTEST_BUNDLE):set -o pipefail swift test --enable-code-coverage | xcbeautify --renderer github-actions + # Merge raw Swift coverage profiles into default.profdata + profraws=(.build/debug/codecov/*.profraw) + if [ ${#profraws[@]} -gt 0 ]; then + llvm-profdata merge -sparse "${profraws[@]}" \ + -o .build/debug/codecov/default.profdata + else + echo "⚠️ No .profraw files found; ensure coverage is enabled" >&2 + exit 1 + fi TEST_BUNDLE=$(find .build/debug/ -name "*.xctest" | head -n 1) TEST_EXECUTABLE="$TEST_BUNDLE/Contents/MacOS/$(basename "$TEST_BUNDLE" .xctest)" xcrun llvm-cov export -format="lcov" \ -instr-profile .build/debug/codecov/default.profdata \ "$TEST_EXECUTABLE" > info.lcovAlso ensure the runner has
llvm-profdataavailable (viabrew install llvmor the Apple toolchain).📝 Committable suggestion