@@ -22,13 +22,19 @@ class SessionCoordinatorTests: XCTestCase {
22
22
var time = MockTimeProvider ( )
23
23
var fireLogger = MockGDTLogger ( )
24
24
var appInfo = MockApplicationInfo ( )
25
+ var sampler = SessionSampler ( )
25
26
26
27
var coordinator : SessionCoordinator !
27
28
28
29
override func setUp( ) {
29
30
super. setUp ( )
30
31
31
- coordinator = SessionCoordinator ( identifiers: identifiers, fireLogger: fireLogger)
32
+ coordinator = SessionCoordinator (
33
+ identifiers: identifiers,
34
+ fireLogger: fireLogger,
35
+ sampler: sampler
36
+ )
37
+ sampler. sessionSamplingRate = 1.0
32
38
}
33
39
34
40
func test_attemptLoggingSessionStart_logsToGDT( ) throws {
@@ -84,4 +90,43 @@ class SessionCoordinatorTests: XCTestCase {
84
90
XCTAssertEqual ( fireLogger. loggedEvent, event)
85
91
XCTAssertFalse ( resultSuccess)
86
92
}
93
+
94
+ func test_eventNotDropped_handlesAllEventsAllowed( ) throws {
95
+ identifiers. mockAllValidIDs ( )
96
+
97
+ let event = SessionStartEvent ( identifiers: identifiers, appInfo: appInfo, time: time)
98
+
99
+ sampler. sessionSamplingRate = 1.0
100
+ var resultSuccess = true
101
+ coordinator. attemptLoggingSessionStart ( event: event) { result in
102
+ switch result {
103
+ case . success( ( ) ) :
104
+ resultSuccess = true
105
+ case . failure:
106
+ resultSuccess = false
107
+ }
108
+ }
109
+
110
+ XCTAssertTrue ( resultSuccess)
111
+ }
112
+
113
+ func test_eventDropped_handlesZeroSamplingRate( ) throws {
114
+ identifiers. mockAllValidIDs ( )
115
+
116
+ let event = SessionStartEvent ( identifiers: identifiers, appInfo: appInfo, time: time)
117
+
118
+ sampler. sessionSamplingRate = 0.0
119
+
120
+ var resultSuccess = true
121
+ coordinator. attemptLoggingSessionStart ( event: event) { result in
122
+ switch result {
123
+ case . success( ( ) ) :
124
+ resultSuccess = true
125
+ case . failure:
126
+ resultSuccess = false
127
+ }
128
+ }
129
+
130
+ XCTAssertFalse ( resultSuccess)
131
+ }
87
132
}
0 commit comments