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

fixes retain cycle #251

Merged
merged 6 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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 SampleApp/DP3TSampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = ch.admin.bag.dp3t.dev;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "dep-3t DEV Deveopment";
PROVISIONING_PROFILE_SPECIFIER = "dep-3t DEV Development";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -402,7 +402,7 @@
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = ch.admin.bag.dp3t.dev;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "dep-3t DEV Deveopment";
PROVISIONING_PROFILE_SPECIFIER = "dep-3t DEV Development";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
2 changes: 1 addition & 1 deletion Sources/DP3TSDK/Background/DP3TBackgroundTaskManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DP3TBackgroundTaskManager {

private let serviceClient: ExposeeServiceClientProtocol

private let tracer: Tracer
private weak var tracer: Tracer!

init(handler: DP3TBackgroundHandler?,
keyProvider: DiagnosisKeysProvider,
Expand Down
2 changes: 1 addition & 1 deletion Sources/DP3TSDK/Tracing/ExposureNotificationTracer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExposureNotificationTracer: Tracer {
private var stateObservation: NSKeyValueObservation?
private var enabledObservation: NSKeyValueObservation?

var delegate: TracerDelegate?
weak var delegate: TracerDelegate?

private let queue = DispatchQueue(label: "org.dpppt.tracer")

Expand Down
2 changes: 1 addition & 1 deletion Sources/DP3TSDK/Tracing/TracerProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protocol TracerDelegate: AnyObject {

public typealias TracingEnableResult = Result<Void, DP3TTracingError>

protocol Tracer {
protocol Tracer: AnyObject {
var delegate: TracerDelegate? { get set }

var state: TrackingState { get }
Expand Down
42 changes: 42 additions & 0 deletions Tests/DP3TSDKTests/DP3TSDKTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,46 @@ class DP3TSDKTests: XCTestCase {

XCTAssertEqual(tracer.state, TrackingState.active)
}

func testInfectedAfterReset() {

XCTAssertEqual(sdk.status.infectionStatus, .healthy)

let firstInfected = expectation(description: "firstInfected")
sdk.iWasExposed(onset: .init(), authentication: .none) { _ in
firstInfected.fulfill()
}
wait(for: [firstInfected], timeout: 1.0)

XCTAssertEqual(sdk.status.infectionStatus, .infected)

sdk.reset()
sdk = nil
//re-init SDK
setUp()

XCTAssertEqual(sdk.status.infectionStatus, .healthy)

let secondInfected = expectation(description: "secondInfected")
sdk.iWasExposed(onset: .init(), authentication: .none) { _ in
secondInfected.fulfill()
}
wait(for: [secondInfected], timeout: 1.0)

XCTAssertEqual(sdk.status.infectionStatus, .infected)
}

func testCorrectDeallocation() {
weak var weakRef = sdk
sdk.reset()
sdk = nil
let expt = expectation(description: "deallocated")

DispatchQueue.main.async {
XCTAssertNil(weakRef)
expt.fulfill()
}

wait(for: [expt], timeout: 1.0)
}
}