Skip to content
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

Adding timing capabilities to clean memory #5

Merged
merged 3 commits into from
Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ConsistencyManager/ConsistencyManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public class ConsistencyManager {
// MARK: Constants

/**
This notification is fired whenever the asyncronous work of clean memory starts.
This notification is fired whenever the asynchronous work of clean memory starts.
It's useful if you want to add timers to this work.
Called on an internal thread.
*/
public static let kCleanMemoryAsynchronousWorkStarted = "com.linkedin.consistencyManager.kCleanMemoryAsynchronousWorkStarted"

/**
This notification is fired whenever the asyncronous work of clean memory finishes.
This notification is fired whenever the asynchronous work of clean memory finishes.
It's useful if you want to add timers to this work.
Called on an internal thread.
*/
Expand Down
3 changes: 3 additions & 0 deletions ConsistencyManagerTests/MemoryWarningTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class MemoryWarningTests: ConsistencyManagerTestCase {


func testMemoryWarning() {
let testStart = NSDate()

NSNotificationCenter.defaultCenter().addObserverForName(ConsistencyManager.kCleanMemoryAsynchronousWorkStarted, object: nil, queue: nil) { _ in
self.cleanMemoryStartedTimes.append(NSDate())
}
Expand Down Expand Up @@ -59,5 +61,6 @@ class MemoryWarningTests: ConsistencyManagerTestCase {
XCTAssertEqual(cleanMemoryStartedTimes.count, 1)
XCTAssertEqual(cleanMemoryFinishedTimes.count, 1)
XCTAssertTrue(cleanMemoryStartedTimes[0].timeIntervalSince1970 <= cleanMemoryFinishedTimes[0].timeIntervalSince1970)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more test case to add to make sure the notifications fire at expected times, register test start time, and at the end assert that cleanMemoryStartedTimes happened after that time.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

XCTAssertTrue(testStart.timeIntervalSinceNow <= cleanMemoryStartedTimes[0].timeIntervalSince1970)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be testStart.timeIntervalSince1970, not timeIntervalSinceNow

}
}