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

fix: some crashes have come up because of logger injection. the reason seems to be the the binder is being updated every inject #387

Merged
merged 4 commits into from
Feb 23, 2021
Merged
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
23 changes: 23 additions & 0 deletions Tests/OptimizelyTests-APIs/OptimizelyClientTests_Others.swift
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,28 @@ class OptimizelyClientTests_Others: XCTestCase {
XCTAssertEqual(newHandlersCount, oldHandlersCount! - 1, "nil handlers should be filtered out")
}

func testGettingLoggerAfterMultiInit() {

let exp = expectation(description: "a")

var optimizely = OptimizelyClient(sdkKey: "a")
for i in 0..<1000 {
DispatchQueue.global().async {
if i == 10 {
optimizely = OptimizelyClient(sdkKey: "b")
}
for k in 0..<10 {
let logger = OPTLoggerFactory.getLogger()
logger.log(level: .info, message: "[LOGGER] [\(i)] \(k)")
}
if i == 999 {
exp.fulfill()
}
}
// need to let the main global queue run otherwise some remained queued.
Thread.sleep(forTimeInterval: 0.02)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This sleep delay breaks the test. 1000 async tasks not concurrent any more because this delay.
If we remove the sleep delay and using DispatchGroup for sync, this test fails because concurrency issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This sleep delay breaks the test. 1000 async tasks not concurrent any more because this delay.
If we remove the sleep delay and using DispatchGroup for sync, this test fails because concurrency issue.

Please add a test if you think it would break. The test won't run all the queued in the global queue without the sleep. So.....

}

wait(for: [exp], timeout: 10)
}
}