Skip to content

Commit

Permalink
test: fix build for E2E test (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
kakcy authored Nov 22, 2023
1 parent 4a5dc0d commit e00ceef
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 41 deletions.
16 changes: 8 additions & 8 deletions Bucketeer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
9340CA0928D9D1DD00E690CC /* EvaluationStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA0828D9D1DD00E690CC /* EvaluationStorageTests.swift */; };
9340CA1928DA0F6200E690CC /* EventSQLDao.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA1628DA0F6200E690CC /* EventSQLDao.swift */; };
9340CA1A28DA0F6200E690CC /* EventEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA1728DA0F6200E690CC /* EventEntity.swift */; };
9340CA1B28DA0F6200E690CC /* EventDaoSQLImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA1828DA0F6200E690CC /* EventDaoSQLImpl.swift */; };
9340CA1F28DA106200E690CC /* EventDaoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA1E28DA106200E690CC /* EventDaoTests.swift */; };
9340CA1B28DA0F6200E690CC /* EventSQLDaoImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA1828DA0F6200E690CC /* EventSQLDaoImpl.swift */; };
9340CA1F28DA106200E690CC /* EventSQLDaoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA1E28DA106200E690CC /* EventSQLDaoTests.swift */; };
9340CA2C28DAEA1500E690CC /* MigrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA2B28DAEA1500E690CC /* MigrationTests.swift */; };
9340CA5928E1CD2600E690CC /* UserHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA5828E1CD2600E690CC /* UserHolder.swift */; };
9340CA5B28E1CE7200E690CC /* BKTUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9340CA5A28E1CE7200E690CC /* BKTUser.swift */; };
Expand Down Expand Up @@ -301,8 +301,8 @@
9340CA0828D9D1DD00E690CC /* EvaluationStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EvaluationStorageTests.swift; sourceTree = "<group>"; };
9340CA1628DA0F6200E690CC /* EventSQLDao.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventSQLDao.swift; sourceTree = "<group>"; };
9340CA1728DA0F6200E690CC /* EventEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventEntity.swift; sourceTree = "<group>"; };
9340CA1828DA0F6200E690CC /* EventDaoSQLImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventDaoSQLImpl.swift; sourceTree = "<group>"; };
9340CA1E28DA106200E690CC /* EventDaoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventDaoTests.swift; sourceTree = "<group>"; };
9340CA1828DA0F6200E690CC /* EventSQLDaoImpl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventSQLDaoImpl.swift; sourceTree = "<group>"; };
9340CA1E28DA106200E690CC /* EventSQLDaoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventSQLDaoTests.swift; sourceTree = "<group>"; };
9340CA2B28DAEA1500E690CC /* MigrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationTests.swift; sourceTree = "<group>"; };
9340CA5828E1CD2600E690CC /* UserHolder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserHolder.swift; sourceTree = "<group>"; };
9340CA5A28E1CE7200E690CC /* BKTUser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BKTUser.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -455,7 +455,7 @@
934889C628EB0ADB007BA05C /* EvaluationForegroundTaskTests.swift */,
006E85C228DED24500B5D90D /* EvaluationInteractorTests.swift */,
935D9AAF28F5B0DB007775F5 /* EvaluationTests.swift */,
9340CA1E28DA106200E690CC /* EventDaoTests.swift */,
9340CA1E28DA106200E690CC /* EventSQLDaoTests.swift */,
937DE95F28E498DF00743FDB /* EventForegroundTaskTests.swift */,
006E85DD28E032E800B5D90D /* EventInteractorTests.swift */,
0065C3F828C81A0D002D92A2 /* JSONDecodingTests.swift */,
Expand Down Expand Up @@ -699,7 +699,7 @@
isa = PBXGroup;
children = (
9340CA1628DA0F6200E690CC /* EventSQLDao.swift */,
9340CA1828DA0F6200E690CC /* EventDaoSQLImpl.swift */,
9340CA1828DA0F6200E690CC /* EventSQLDaoImpl.swift */,
9340CA1728DA0F6200E690CC /* EventEntity.swift */,
006E85CD28DEE23100B5D90D /* EventInteractor.swift */,
);
Expand Down Expand Up @@ -1118,7 +1118,7 @@
0065C3E328C8136D002D92A2 /* Event.swift in Sources */,
004CF1F32929C9E500CCC3DF /* EventBackgroundTask.swift in Sources */,
9340CA1928DA0F6200E690CC /* EventSQLDao.swift in Sources */,
9340CA1B28DA0F6200E690CC /* EventDaoSQLImpl.swift in Sources */,
9340CA1B28DA0F6200E690CC /* EventSQLDaoImpl.swift in Sources */,
946540372A821A11009BF89F /* EvaluationMemCacheDao.swift in Sources */,
0065C3E528C813D6002D92A2 /* EventData.swift in Sources */,
9340CA1A28DA0F6200E690CC /* EventEntity.swift in Sources */,
Expand Down Expand Up @@ -1175,7 +1175,7 @@
934889C728EB0ADB007BA05C /* EvaluationForegroundTaskTests.swift in Sources */,
006E85C328DED24500B5D90D /* EvaluationInteractorTests.swift in Sources */,
935D9AB028F5B0DB007775F5 /* EvaluationTests.swift in Sources */,
9340CA1F28DA106200E690CC /* EventDaoTests.swift in Sources */,
9340CA1F28DA106200E690CC /* EventSQLDaoTests.swift in Sources */,
937DE96028E498E000743FDB /* EventForegroundTaskTests.swift in Sources */,
006E85DE28E032E800B5D90D /* EventInteractorTests.swift in Sources */,
0065C3F928C81A0D002D92A2 /* JSONDecodingTests.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Bucketeer/Sources/Internal/DI/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class ComponentImpl: Component {
device: dataModule.device,
eventsMaxBatchQueueCount: dataModule.config.eventsMaxQueueSize,
apiClient: dataModule.apiClient,
eventDao: dataModule.eventSQLDao,
eventSQLDao: dataModule.eventSQLDao,
clock: dataModule.clock,
idGenerator: dataModule.idGenerator,
logger: dataModule.config.logger,
Expand Down
2 changes: 1 addition & 1 deletion Bucketeer/Sources/Internal/DI/DataModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class DataModuleImpl: DataModule {
self.config = config
self.sqlite = try DatabaseOpenHelper.createDatabase(logger: config.logger)
self.evaluationDao = EvaluationSQLDaoImpl(db: sqlite)
self.eventSQLDao = EventDaoSQLImpl(db: sqlite)
self.eventSQLDao = EventSQLDaoImpl(db: sqlite)
}

private(set) lazy var clock: Clock = ClockImpl()
Expand Down
24 changes: 12 additions & 12 deletions Bucketeer/Sources/Internal/Event/EventInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class EventInteractorImpl: EventInteractor {
let sdkVersion: String
let eventsMaxBatchQueueCount: Int
let apiClient: ApiClient
let eventDao: EventSQLDao
let eventSQLDao: EventSQLDao
let clock: Clock
let idGenerator: IdGenerator
let logger: Logger?
Expand All @@ -36,7 +36,7 @@ final class EventInteractorImpl: EventInteractor {
device: Device,
eventsMaxBatchQueueCount: Int,
apiClient: ApiClient,
eventDao: EventSQLDao,
eventSQLDao: EventSQLDao,
clock: Clock,
idGenerator: IdGenerator,
logger: Logger?,
Expand All @@ -45,7 +45,7 @@ final class EventInteractorImpl: EventInteractor {
self.sdkVersion = sdkVersion
self.eventsMaxBatchQueueCount = eventsMaxBatchQueueCount
self.apiClient = apiClient
self.eventDao = eventDao
self.eventSQLDao = eventSQLDao
self.clock = clock
self.idGenerator = idGenerator
self.logger = logger
Expand All @@ -63,7 +63,7 @@ final class EventInteractorImpl: EventInteractor {
}

func trackEvaluationEvent(featureTag: String, user: User, evaluation: Evaluation) throws {
try eventDao.add(
try eventSQLDao.add(
event: .init(
id: idGenerator.id(),
event: .evaluation(.init(
Expand All @@ -86,7 +86,7 @@ final class EventInteractorImpl: EventInteractor {
}

func trackDefaultEvaluationEvent(featureTag: String, user: User, featureId: String) throws {
try eventDao.add(
try eventSQLDao.add(
event: .init(
id: idGenerator.id(),
event: .evaluation(.init(
Expand All @@ -107,7 +107,7 @@ final class EventInteractorImpl: EventInteractor {
}

func trackGoalEvent(featureTag: String, user: User, goalId: String, value: Double) throws {
try eventDao.add(
try eventSQLDao.add(
event: .init(
id: idGenerator.id(),
event: .goal(.init(
Expand All @@ -128,7 +128,7 @@ final class EventInteractorImpl: EventInteractor {
}

func trackFetchEvaluationsSuccess(featureTag: String, seconds: Double, sizeByte: Int64) throws {
try eventDao.add(
try eventSQLDao.add(
events: [
.init(
id: idGenerator.id(),
Expand Down Expand Up @@ -204,7 +204,7 @@ final class EventInteractorImpl: EventInteractor {

private func trackMetricsEvent(events: [Event]) throws {
// We will add logic to filter duplicate metrics event here
let storedEvents = try eventDao.getEvents()
let storedEvents = try eventSQLDao.getEvents()
let metricsEventUniqueKeys: [String] = storedEvents.filter { item in
return item.isMetricEvent()
}.map { item in
Expand All @@ -214,7 +214,7 @@ final class EventInteractorImpl: EventInteractor {
return item.isMetricEvent() && !metricsEventUniqueKeys.contains(item.uniqueKey())
}
if newEvents.count > 0 {
try eventDao.add(events: newEvents)
try eventSQLDao.add(events: newEvents)
updateEventsAndNotify()
} else {
logger?.debug(message: "no new events to add")
Expand All @@ -224,7 +224,7 @@ final class EventInteractorImpl: EventInteractor {
func sendEvents(force: Bool, completion: ((Result<Bool, BKTError>) -> Void)?) {
logger?.debug(message:"sendEvents called")
do {
let currentEvents = try eventDao.getEvents()
let currentEvents = try eventSQLDao.getEvents()
guard !currentEvents.isEmpty else {
logger?.debug(message: "no events to register")
completion?(.success(false))
Expand Down Expand Up @@ -253,7 +253,7 @@ final class EventInteractorImpl: EventInteractor {
return !error.retriable
})
do {
try self?.eventDao.delete(ids: deletedIds)
try self?.eventSQLDao.delete(ids: deletedIds)
self?.updateEventsAndNotify()
completion?(.success(true))
} catch let error {
Expand All @@ -276,7 +276,7 @@ final class EventInteractorImpl: EventInteractor {
private func updateEventsAndNotify() {
guard eventUpdateListener != nil else { return }
do {
let events = try eventDao.getEvents()
let events = try eventSQLDao.getEvents()
eventUpdateListener?.onUpdate(events: events)
} catch let error {
logger?.error(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

final class EventDaoSQLImpl: EventSQLDao {
final class EventSQLDaoImpl: EventSQLDao {
private let db: SQLite

init(db: SQLite) {
Expand Down
11 changes: 5 additions & 6 deletions BucketeerTests/E2E/E2EEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ final class E2EEventTests: XCTestCase {

// getVariationValue() is logging events using another dispatch queue, we need to wait a few secs
try await Task.sleep(nanoseconds: 10_000_000)
let events = try component.dataModule.eventDao.getEvents()
let events = try component.dataModule.eventSQLDao.getEvents()
// It includes the Latency and ResponseSize metrics
XCTAssertEqual(events.count, 7)
XCTAssertTrue(events.contains { event in
Expand All @@ -73,7 +73,7 @@ final class E2EEventTests: XCTestCase {

try await client.flush()

XCTAssertEqual(try component.dataModule.eventDao.getEvents().count, 0)
XCTAssertEqual(try component.dataModule.eventSQLDao.getEvents().count, 0)
} catch {
XCTFail(error.localizedDescription)
}
Expand All @@ -86,11 +86,10 @@ final class E2EEventTests: XCTestCase {
XCTFail("could not access client.component")
return
}
let userId = client.component.userHolder.userId
try await withCheckedThrowingContinuation({ continuation in
client.execute {
do {
try component.dataModule.evaluationStorage.deleteAllAndInsert(userId: userId, evaluations: [], evaluatedAt: "0")
try component.dataModule.evaluationStorage.deleteAllAndInsert(evaluationId: "evaluationId", evaluations: [], evaluatedAt: "0")
continuation.resume(returning: ())
} catch {
continuation.resume(throwing: error)
Expand All @@ -110,7 +109,7 @@ final class E2EEventTests: XCTestCase {

// getVariationValue() is logging events using another dispatch queue, we need to wait a few secs
try await Task.sleep(nanoseconds: 10_000_000)
let events = try component.dataModule.eventDao.getEvents()
let events = try component.dataModule.eventSQLDao.getEvents()
// It includes the Latency and ResponseSize metrics
XCTAssertEqual(events.count, 7)
XCTAssertTrue(events.contains { event in
Expand All @@ -124,7 +123,7 @@ final class E2EEventTests: XCTestCase {

try await client.flush()

XCTAssertEqual(try component.dataModule.eventDao.getEvents().count, 0)
XCTAssertEqual(try component.dataModule.eventSQLDao.getEvents().count, 0)
} catch {
XCTFail(error.localizedDescription)
}
Expand Down
8 changes: 4 additions & 4 deletions BucketeerTests/E2E/E2EMetricsEventTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class E2EMetricsEventTests: XCTestCase {
XCTFail("could not access client.component")
return
}
let events : [Event] = try component.dataModule.eventDao.getEvents()
let events : [Event] = try component.dataModule.eventSQLDao.getEvents()
// It includes the Latency and ResponseSize metrics
XCTAssertEqual(events.count, 1)
XCTAssertTrue(events.contains { event in
Expand All @@ -73,7 +73,7 @@ final class E2EMetricsEventTests: XCTestCase {
}
}

let events2 : [Event] = try component.dataModule.eventDao.getEvents()
let events2 : [Event] = try component.dataModule.eventSQLDao.getEvents()
// It includes the Latency and ResponseSize metrics
XCTAssertEqual(events2.count, 2)
}
Expand Down Expand Up @@ -114,7 +114,7 @@ final class E2EMetricsEventTests: XCTestCase {
XCTFail("could not access client.component")
return
}
let events : [Event] = try component.dataModule.eventDao.getEvents()
let events : [Event] = try component.dataModule.eventSQLDao.getEvents()
XCTAssertEqual(events.count, 1)
XCTAssertTrue(events.contains { event in
if case .metrics = event.type,
Expand All @@ -129,6 +129,6 @@ final class E2EMetricsEventTests: XCTestCase {

try await client.flush()

XCTAssertEqual(try component.dataModule.eventDao.getEvents().count, 0)
XCTAssertEqual(try component.dataModule.eventSQLDao.getEvents().count, 0)
}
}
2 changes: 1 addition & 1 deletion BucketeerTests/EventInteractorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class EventInteractorTests: XCTestCase {
device: MockDevice(),
eventsMaxBatchQueueCount: 3,
apiClient: api,
eventDao: dao,
eventSQLDao: dao,
clock: clock,
idGenerator: idGenerator,
logger: logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import XCTest
@testable import Bucketeer

@available(iOS 13, *)
final class EventDaoTests: XCTestCase {
final class EventSQLDaoTests: XCTestCase {
let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("event_test.db")
var path: String { url.path }

Expand All @@ -23,7 +23,7 @@ final class EventDaoTests: XCTestCase {

func testAddEventGoal() throws {
let db = try SQLite(path: path, logger: nil)
let dao = EventDaoSQLImpl(db: db)
let dao = EventSQLDaoImpl(db: db)

try dao.add(event: .mockGoal1)

Expand All @@ -45,7 +45,7 @@ final class EventDaoTests: XCTestCase {

func testAddEventEvaluation() throws {
let db = try SQLite(path: path, logger: nil)
let dao = EventDaoSQLImpl(db: db)
let dao = EventSQLDaoImpl(db: db)

try dao.add(event: .mockEvaluation1)

Expand All @@ -67,7 +67,7 @@ final class EventDaoTests: XCTestCase {

func testAddEventMetrics() throws {
let db = try SQLite(path: path, logger: nil)
let dao = EventDaoSQLImpl(db: db)
let dao = EventSQLDaoImpl(db: db)

try dao.add(event: .mockMetricsResponseLatency1)

Expand All @@ -89,7 +89,7 @@ final class EventDaoTests: XCTestCase {

func testAddEvents() throws {
let db = try SQLite(path: path, logger: nil)
let dao = EventDaoSQLImpl(db: db)
let dao = EventSQLDaoImpl(db: db)

try dao.add(events: [.mockGoal1, .mockEvaluation1, .mockMetricsResponseLatency1, .mockEvaluation2])

Expand All @@ -103,7 +103,7 @@ final class EventDaoTests: XCTestCase {

func testDeleteAll() throws {
let db = try SQLite(path: path, logger: nil)
let dao = EventDaoSQLImpl(db: db)
let dao = EventSQLDaoImpl(db: db)
let target: [Event] = [.mockGoal1, .mockEvaluation1, .mockMetricsResponseLatency1, .mockEvaluation2]
try dao.add(events: target)

Expand All @@ -116,7 +116,7 @@ final class EventDaoTests: XCTestCase {

func testDeleteSomeItems() throws {
let db = try SQLite(path: path, logger: nil)
let dao = EventDaoSQLImpl(db: db)
let dao = EventSQLDaoImpl(db: db)
let target: [Event] = [.mockGoal1, .mockEvaluation1, .mockMetricsResponseLatency1, .mockEvaluation2]
try dao.add(events: target)

Expand Down

0 comments on commit e00ceef

Please sign in to comment.