-
Notifications
You must be signed in to change notification settings - Fork 133
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
RUM-2355 fix: Network Instrumentation #1588
Changes from all commits
3fd3c25
1143e1c
6f90704
7168a9c
7948805
7854ae2
1af3f9a
ec07865
00bf6cc
9c6ab65
519646f
ef7a846
b8a1eb5
5b43ff1
738d599
9e46d77
a45c90e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ internal class DatadogTestsObserver: NSObject, XCTestObservation { | |
Make sure all applied swizzling are reset by the end of test with `unswizzle()`. | ||
|
||
`DatadogTestsObserver` found \(Swizzling.methods.count) leaked swizzlings: | ||
\(Swizzling.methods) | ||
\(Swizzling.description) | ||
""" | ||
), | ||
.init( | ||
|
@@ -132,34 +132,6 @@ internal class DatadogTestsObserver: NSObject, XCTestObservation { | |
|
||
If all above conditions are met, this failure might indicate a memory leak in the implementation. | ||
""" | ||
), | ||
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. Removing these checks seems like a back step - in case of a memory leak we will not able to catch any lingering swizzlings. A check something like if there is an instance of swizzler in memory or not will be helpful. something like func checkInstancesOfType(_ type: AnyClass) -> Bool {
let typeString = String(describing: type)
for bundle in Bundle.allBundles {
if let className = bundle.classNamed(typeString) {
// Check if an instance of the class exists
if class_getInstanceSize(className) > 0 {
return true
}
}
}
return false
} 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. It is already there, see my comment. These checks were redundant, we are already asserting that no swizzling is left here. Failure will print the method signature, so we will know which sizzling is at fault. |
||
.init( | ||
assert: { URLSessionTaskDelegateSwizzler.isBinded == false }, | ||
problem: "No URLSessionTaskDelegate swizzling must be applied.", | ||
solution: """ | ||
Make sure all the binded delegates are unbinded by the end of test with `URLSessionTaskDelegateSwizzler.unbind(delegate:)`. | ||
""" | ||
), | ||
.init( | ||
assert: { URLSessionDataDelegateSwizzler.isBinded == false }, | ||
problem: "No URLSessionDataDelegate swizzling must be applied.", | ||
solution: """ | ||
Make sure all the binded delegates are unbinded by the end of test with `URLSessionDataDelegateSwizzler.unbind(delegate:)`. | ||
""" | ||
), | ||
.init( | ||
assert: { URLSessionTaskSwizzler.isBinded == false }, | ||
problem: "No URLSessionTask swizzling must be applied.", | ||
solution: """ | ||
Make sure all the binded delegates are unbinded by the end of test with `URLSessionTaskSwizzler.unbind()`. | ||
""" | ||
), | ||
.init( | ||
assert: { URLSessionSwizzler.isBinded == false }, | ||
problem: "No URLSession swizzling must be applied.", | ||
solution: """ | ||
Make sure all the binded delegates are unbinded by the end of test with `URLSessionSwizzler.unbind()`. | ||
""" | ||
) | ||
] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,20 +39,16 @@ public final class ReadWriteLock<Value> { | |
defer { pthread_rwlock_unlock(&rwlock) } | ||
return value | ||
} | ||
set { | ||
pthread_rwlock_wrlock(&rwlock) | ||
value = newValue | ||
pthread_rwlock_unlock(&rwlock) | ||
} | ||
set { mutate { $0 = newValue } } | ||
} | ||
|
||
/// Provides a non-escaping closure for mutation. | ||
/// The lock will be acquired once for writing before invoking the closure. | ||
/// | ||
/// - Parameter closure: The closure with the mutable value. | ||
public func mutate(_ closure: (inout Value) -> Void) { | ||
public func mutate(_ closure: (inout Value) throws -> Void) rethrows { | ||
pthread_rwlock_wrlock(&rwlock) | ||
closure(&value) | ||
pthread_rwlock_unlock(&rwlock) | ||
defer { pthread_rwlock_unlock(&rwlock) } | ||
try closure(&value) | ||
Comment on lines
-42
to
+52
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. Not related, but better :) |
||
} | ||
} |
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.
blocking/ The new logic introduces new global swizzlings that need to be covered in integrity checks. Here we remove old checks instead of updating them ⛔. Balancing following calls must be enforced by
DatadogTestsObserver
, otherwise we will run into flakiness ❄️: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.
Previously, it was actually covered twice. Swizzling integrity is already checked by this which will fail if any swizzling is left, printing the method signatures 👍
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.
Nice, can you add some simple test case?
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.
I have added this to
MethodSwizzlerTests
👍