@@ -46,7 +46,7 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
46
46
47
47
// MARK: - "Batch Deleted" Metric
48
48
49
- func testWhenReadableFileIsDeleted_itSendsBatchDeletedMetric ( ) throws {
49
+ func testWhenReadableFileIsDeleted_itSendsTelemetryMetric ( ) throws {
50
50
// Given
51
51
let orchestrator = createOrchestrator ( )
52
52
let expectedBatchAge = storage. minFileAgeForRead + 1
@@ -63,8 +63,8 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
63
63
orchestrator. delete ( readableFile: file, deletionReason: . intakeCode( responseCode: 202 ) )
64
64
65
65
// Then
66
- let metric = try XCTUnwrap ( telemetry. messages. firstMetricReport ( named: " Batch Deleted " ) )
67
- DDAssertJSONEqual ( metric . attributes, [
66
+ let batchDeleted = try XCTUnwrap ( telemetry. messages. firstMetricReport ( named: " Batch Deleted " ) )
67
+ DDAssertJSONEqual ( batchDeleted . attributes, [
68
68
" metric_type " : " batch deleted " ,
69
69
" track " : " track name " ,
70
70
" consent " : " consent value " ,
@@ -76,13 +76,20 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
76
76
" in_background " : false ,
77
77
" background_tasks_enabled " : false ,
78
78
" batch_age " : expectedBatchAge. toMilliseconds,
79
- " batch_removal_reason " : " intake-code-202 " ,
80
- " pending_batches " : 1
79
+ " batch_removal_reason " : " intake-code-202 "
81
80
] )
82
- XCTAssertEqual ( metric. sampleRate, BatchDeletedMetric . sampleRate)
81
+ XCTAssertEqual ( batchDeleted. sampleRate, BatchDeletedMetric . sampleRate)
82
+
83
+ let pendingBatches = telemetry. messages. compactMap { $0. asMetricIncrement } . reduce ( 0 ) { count, metric in
84
+ XCTAssertEqual ( metric. metric, " pending batches " )
85
+ XCTAssertEqual ( metric. cardinalities [ " track " ] , . string( " track name " ) )
86
+ return count + metric. increment
87
+ }
88
+
89
+ XCTAssertEqual ( pendingBatches, 1 )
83
90
}
84
91
85
- func testWhenObsoleteFileIsDeleted_itSendsBatchDeletedMetric ( ) throws {
92
+ func testWhenObsoleteFileIsDeleted_itSendsTelemetryMetric ( ) throws {
86
93
// Given:
87
94
// - request some batch to be created
88
95
let orchestrator = createOrchestrator ( )
@@ -95,8 +102,8 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
95
102
_ = orchestrator. getReadableFiles ( )
96
103
97
104
// Then
98
- let metric = try XCTUnwrap ( telemetry. messages. firstMetricReport ( named: " Batch Deleted " ) )
99
- DDAssertJSONEqual ( metric . attributes, [
105
+ let batchDeleted = try XCTUnwrap ( telemetry. messages. firstMetricReport ( named: " Batch Deleted " ) )
106
+ DDAssertJSONEqual ( batchDeleted . attributes, [
100
107
" metric_type " : " batch deleted " ,
101
108
" track " : " track name " ,
102
109
" consent " : " consent value " ,
@@ -108,13 +115,29 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
108
115
" in_background " : false ,
109
116
" background_tasks_enabled " : false ,
110
117
" batch_age " : ( storage. maxFileAgeForRead + 1 ) . toMilliseconds,
111
- " batch_removal_reason " : " obsolete " ,
112
- " pending_batches " : 0
118
+ " batch_removal_reason " : " obsolete "
113
119
] )
114
- XCTAssertEqual ( metric. sampleRate, BatchDeletedMetric . sampleRate)
120
+ XCTAssertEqual ( batchDeleted. sampleRate, BatchDeletedMetric . sampleRate)
121
+
122
+ let pendingBatches = telemetry. messages. reduce ( 0 ) { count, message in
123
+ switch message {
124
+ case let . metric( . record( metric, value, cardinalities) ) :
125
+ XCTAssertEqual ( metric, " pending batches " )
126
+ XCTAssertEqual ( cardinalities [ " track " ] , . string( " track name " ) )
127
+ return value
128
+ case let . metric( . increment( metric, value, cardinalities) ) :
129
+ XCTAssertEqual ( metric, " pending batches " )
130
+ XCTAssertEqual ( cardinalities [ " track " ] , . string( " track name " ) )
131
+ return count + value
132
+ default :
133
+ return count
134
+ }
135
+ }
136
+
137
+ XCTAssertEqual ( pendingBatches, 0 )
115
138
}
116
139
117
- func testWhenDirectoryIsPurged_itSendsBatchDeletedMetrics ( ) throws {
140
+ func testWhenDirectoryIsPurged_itSendsTelemetryMetrics ( ) throws {
118
141
// Given: some batch
119
142
// - request batch to be created
120
143
// - write more data than allowed directory size limit
@@ -130,8 +153,8 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
130
153
_ = try orchestrator. getWritableFile ( writeSize: 1 )
131
154
132
155
// Then
133
- let metric = try XCTUnwrap ( telemetry. messages. firstMetricReport ( named: " Batch Deleted " ) )
134
- DDAssertJSONEqual ( metric . attributes, [
156
+ let batchDeleted = try XCTUnwrap ( telemetry. messages. firstMetricReport ( named: " Batch Deleted " ) )
157
+ DDAssertJSONEqual ( batchDeleted . attributes, [
135
158
" metric_type " : " batch deleted " ,
136
159
" track " : " track name " ,
137
160
" consent " : " consent value " ,
@@ -143,10 +166,17 @@ class FilesOrchestrator_MetricsTests: XCTestCase {
143
166
" in_background " : false ,
144
167
" background_tasks_enabled " : false ,
145
168
" batch_age " : expectedBatchAge. toMilliseconds,
146
- " batch_removal_reason " : " purged " ,
147
- " pending_batches " : 0
169
+ " batch_removal_reason " : " purged "
148
170
] )
149
- XCTAssertEqual ( metric. sampleRate, BatchDeletedMetric . sampleRate)
171
+ XCTAssertEqual ( batchDeleted. sampleRate, BatchDeletedMetric . sampleRate)
172
+
173
+ let pendingBatches = telemetry. messages. compactMap { $0. asMetricIncrement } . reduce ( 0 ) { count, metric in
174
+ XCTAssertEqual ( metric. metric, " pending batches " )
175
+ XCTAssertEqual ( metric. cardinalities [ " track " ] , . string( " track name " ) )
176
+ return count + metric. increment
177
+ }
178
+
179
+ XCTAssertEqual ( pendingBatches, 1 )
150
180
}
151
181
152
182
// MARK: - "Batch Closed" Metric
0 commit comments