Skip to content

Commit

Permalink
Merge pull request #251 from DP-3T/bugfix/retain-cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
UBaggeler authored May 12, 2021
2 parents 357f7a1 + 7efb508 commit e0f2149
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
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)
}
}

0 comments on commit e0f2149

Please sign in to comment.