Skip to content

Commit

Permalink
Merge pull request #2 from tarunon/feature/interval_for_release
Browse files Browse the repository at this point in the history
Add interval for object freeing
  • Loading branch information
tarunon authored Apr 25, 2019
2 parents 40b247b + 30128e1 commit 5ca5560
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/XCTAssertNoLeak/Core/Assert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func assertNoLeak(_ object: @autoclosure () -> AnyObject, assert: (String, Stati
node = Node(from: strongObject!)
strongObject = nil
}
RunLoop.current.run(until: Date(timeIntervalSinceNow: node.intervalForFreeing()))
node.leakedObjectPaths().forEach { (path) in
assert(makeAssertMessage(path: path.pathString(with: "self")), file, line)
}
Expand All @@ -42,6 +43,7 @@ func assertNoLeak(_ f: (Context) -> (), assert: @escaping (String, StaticString,
RunLoop.current.run(until: Date(timeIntervalSinceNow: 0.01))
}
}
RunLoop.current.run(until: Date(timeIntervalSinceNow: nodes.reduce(TimeInterval(0.0), { $0 + $1.node.intervalForFreeing() })))
nodes.forEach { element in
element.node.leakedObjectPaths().forEach { path in
assert(makeAssertMessage(path: path.pathString(with: element.name)), element.file, element.line)
Expand Down
6 changes: 6 additions & 0 deletions Sources/XCTAssertNoLeak/Core/CustomTraversable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public protocol CustomTraversable {
/// Ignore object assertion if memory leak happen.
/// Set true if the object is singleton/shared object.
var ignoreAssertion: Bool { get }

/// Waiting interval for the object freeing.
var intervalForFreeing: TimeInterval { get }
}

public extension CustomTraversable {
Expand All @@ -24,4 +27,7 @@ public extension CustomTraversable {
var ignoreAssertion: Bool {
return false
}
var intervalForFreeing: TimeInterval {
return 0.0
}
}
4 changes: 4 additions & 0 deletions Sources/XCTAssertNoLeak/Core/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,8 @@ class Node {
return node.allPaths().map { [path] + $0 }
}
}

func intervalForFreeing() -> TimeInterval {
return children.values.reduce((object as? CustomTraversable)?.intervalForFreeing ?? 0.0, { $0 + $1.intervalForFreeing() })
}
}

0 comments on commit 5ca5560

Please sign in to comment.