Skip to content

Commit

Permalink
fix: fix interval policy test
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjcharles committed Oct 3, 2023
1 parent 34625e8 commit 87070d8
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions Tests/Segment-Tests/FlushPolicy_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,45 +122,26 @@ class FlushPolicyTests: XCTestCase {

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

//remove default flush policies
analytics.removeAllFlushPolicies()

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

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

waitUntilStarted(analytics: analytics)
//let event = TrackEvent(event: "blah", properties: nil)
analytics.track(name: "blah", properties: nil)

let hasUnsent = analytics.hasUnsentEvents
XCTAssertTrue(hasUnsent)

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

let hasUnsent2 = analytics.hasUnsentEvents
XCTAssertFalse(hasUnsent2)
}

// Ignore, previous test
// func testIntervalBasedFlushPolicy() throws {
// let analytics = Analytics(configuration: Configuration(writeKey: "intervalFlushPolicy"))
// let intervalFlush = IntervalBasedFlushPolicy(interval: 4000)
// analytics.add(flushPolicy: intervalFlush)
//
// waitUntilStarted(analytics: analytics)
//
// let event = TrackEvent(event: "blah", properties: nil)
//
// // 1
// intervalFlush.updateState(event: event)
// XCTAssertFalse(intervalFlush.shouldFlush())
//
// let exp = expectation(description: "Test after 5 seconds")
// let result = XCTWaiter.wait(for: [exp], timeout: 5)
//
// if result == XCTWaiter.Result.timedOut {
// XCTAssertTrue(intervalFlush.shouldFlush())
// } else {
// XCTFail("Delay interrupted")
// }
// }

}

0 comments on commit 87070d8

Please sign in to comment.