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

Update Flush policies #256

Merged
merged 4 commits into from
Oct 4, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class CountBasedFlushPolicy: FlushPolicy {
internal var desiredCount: Int?
@Atomic internal var count: Int = 0

init() { }
public init() { }

init(count: Int) {
public init(count: Int) {
desiredCount = count
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class IntervalBasedFlushPolicy: FlushPolicy,
internal var desiredInterval: TimeInterval?
internal var flushTimer: QueueTimer? = nil

init() { }
public init() { }

init(interval: TimeInterval) {
public init(interval: TimeInterval) {
desiredInterval = interval
}

Expand Down
23 changes: 23 additions & 0 deletions Tests/Segment-Tests/FlushPolicy_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,27 @@ class FlushPolicyTests: XCTestCase {
// we now have ONE HA HA. TWO HA HA .. 3 ... HA HA THREE! Items to flush! <flys aways>
XCTAssertTrue(countFlush.shouldFlush())
}

func testIntervalBasedFlushPolicy() throws {
let analytics = Analytics(configuration: Configuration(writeKey: "intervalFlushPolicy"))

//remove default flush policies
analytics.removeAllFlushPolicies()

// make sure storage has no old events
analytics.storage.hardReset(doYouKnowHowToUseThis: true)

let intervalFlush = IntervalBasedFlushPolicy(interval: 2)
analytics.add(flushPolicy: intervalFlush)

waitUntilStarted(analytics: analytics)
analytics.track(name: "blah", properties: nil)

XCTAssertTrue(analytics.hasUnsentEvents)

// sleep for 4 seconds for 2 second flush policy
RunLoop.main.run(until: Date.init(timeIntervalSinceNow: 4))

XCTAssertFalse(analytics.hasUnsentEvents)
}
}
Loading