@@ -118,10 +118,10 @@ def test_metrics
118
118
callback . wait_until_ready
119
119
120
120
# Here we test register_evaluation then run_one_iteration
121
- ( 1 ..3 ) . each { metrics_processor . register_evaluation @target , @feature1 , @variation1 }
122
- ( 1 ..3 ) . each { metrics_processor . register_evaluation @target , @feature1 , @variation2 }
123
- ( 1 ..3 ) . each { metrics_processor . register_evaluation @target , @feature2 , @variation1 }
124
- ( 1 ..3 ) . each { metrics_processor . register_evaluation @target , @feature2 , @variation2 }
121
+ ( 1 ..3 ) . each { metrics_processor . register_evaluation @target , @feature1 . feature , @variation1 . identifier }
122
+ ( 1 ..3 ) . each { metrics_processor . register_evaluation @target , @feature1 . feature , @variation2 . identifier }
123
+ ( 1 ..3 ) . each { metrics_processor . register_evaluation @target , @feature2 . feature , @variation1 . identifier }
124
+ ( 1 ..3 ) . each { metrics_processor . register_evaluation @target , @feature2 . feature , @variation2 . identifier }
125
125
126
126
freq_map = metrics_processor . send :get_frequency_map
127
127
assert_equal 4 , freq_map . size , "not enough pending metrics"
@@ -162,18 +162,8 @@ def config.logger
162
162
163
163
# Register evaluations
164
164
( 1 ..10 ) . each do |i |
165
- feature = OpenapiClient ::FeatureConfig . new
166
- feature . feature = "feature-#{ i } "
167
- variation = OpenapiClient ::Variation . new
168
- variation . identifier = "variation-#{ i } "
169
- variation . value = "value-#{ i } "
170
- variation . name = "Test-#{ i } "
171
-
172
- variation2 = OpenapiClient ::Variation . new
173
- variation2 . identifier = "variation2-#{ i } "
174
- variation2 . value = "value2-#{ i } "
175
- variation2 . name = "Test2-#{ i } "
176
- feature . variations = [ variation , @variation2 ]
165
+ feature = "feature-#{ i } "
166
+ variation = "variation-#{ i } "
177
167
metrics_processor . register_evaluation ( @target , feature , variation )
178
168
end
179
169
@@ -258,19 +248,9 @@ def config.logger
258
248
259
249
# Define a method to register evaluations
260
250
register_evals = Proc . new do |feature_id |
261
- feature = OpenapiClient ::FeatureConfig . new
262
- feature . feature = "feature-#{ feature_id } "
263
- variation = OpenapiClient ::Variation . new
264
- variation . identifier = "variation-#{ feature_id } "
265
- variation . value = "value-#{ feature_id } "
266
- variation . name = "Test-#{ feature_id } "
267
-
268
- variation2 = OpenapiClient ::Variation . new
269
- variation2 . identifier = "variation2-#{ feature_id } "
270
- variation2 . value = "value2-#{ feature_id } "
271
- variation2 . name = "Test2-#{ feature_id } "
272
-
273
- feature . variations = [ variation , variation2 ]
251
+ feature = "feature-#{ feature_id } "
252
+ variation = "variation-#{ feature_id } "
253
+
274
254
metrics_processor . register_evaluation ( @target , feature , variation )
275
255
end
276
256
@@ -316,13 +296,11 @@ def config.logger
316
296
metric_found = { }
317
297
expected_metrics_set . each { |metric | metric_found [ metric ] = false }
318
298
319
- freq_map . each_key do |metrics_event |
320
- # Extract feature name and variation identifier from the metrics_event
321
- actual_feature_name = metrics_event . feature_config . feature
322
- actual_variation_id = metrics_event . variation . identifier
299
+ freq_map . each_key do |key |
300
+ feature_name , variation_identifier = key . split ( "\0 " , 2 )
323
301
324
302
# Create the key for the current metric
325
- metric_key = [ actual_feature_name , actual_variation_id ]
303
+ metric_key = [ feature_name , variation_identifier ]
326
304
327
305
if metric_found . key? ( metric_key )
328
306
metric_found [ metric_key ] = true
@@ -353,19 +331,9 @@ def config.logger
353
331
callback . wait_until_ready
354
332
355
333
# Register some evaluations
356
- feature = OpenapiClient ::FeatureConfig . new
357
- feature . feature = "feature-error-test"
358
- variation = OpenapiClient ::Variation . new
359
- variation . identifier = "variation-error-test"
360
- variation . value = "value-error-test"
361
- variation . name = "Test-Error"
362
-
363
- variation2 = OpenapiClient ::Variation . new
364
- variation2 . identifier = "variation2-error-test"
365
- variation2 . value = "value2-error-test"
366
- variation2 . name = "Test2-Error"
367
-
368
- feature . variations = [ variation , variation2 ]
334
+ feature = "feature-error-test"
335
+ variation = "variation-error-test"
336
+
369
337
metrics_processor . register_evaluation ( @target , feature , variation )
370
338
371
339
# Attempt to send data, which should raise an exception
@@ -379,18 +347,10 @@ def config.logger
379
347
assert_empty target_metrics_map , "Target metrics map should be cleared even if an error occurs"
380
348
381
349
# Verify that the MetricsProcessor remains operational by registering another evaluation
382
- feature_new = OpenapiClient ::FeatureConfig . new
383
- feature_new . feature = "feature-new"
384
- variation_new = OpenapiClient ::Variation . new
385
- variation_new . identifier = "variation-new"
386
- variation_new . value = "value-new"
387
- variation_new . name = "Test-New"
388
-
389
- variation2_new = OpenapiClient ::Variation . new
390
- variation2_new . identifier = "variation2-new"
391
- variation2_new . value = "value2-new"
392
- variation2_new . name = "Test2-New"
393
- metrics_processor . register_evaluation ( @target , feature , variation )
350
+ feature_new = "feature-new"
351
+ variation_new = "variation-new"
352
+
353
+ metrics_processor . register_evaluation ( @target , feature_new , variation_new )
394
354
395
355
# Ensure that the new evaluation is registered correctly
396
356
freq_map = metrics_processor . send ( :get_frequency_map )
@@ -465,18 +425,6 @@ def assert_target_data(target_data)
465
425
assert targets . key? ( "target-id" )
466
426
end
467
427
468
- def test_comparable_metrics_event_equals_and_hash
469
-
470
- event1 = MetricsEvent . new ( @feature1 , @target , @variation1 , Logger . new ( STDOUT ) )
471
- event2 = MetricsEvent . new ( @feature1 , @target , @variation1 , Logger . new ( STDOUT ) )
472
-
473
- assert ( event1 == event2 )
474
-
475
- event1 = MetricsEvent . new ( @feature1 , @target , @variation1 , Logger . new ( STDOUT ) )
476
- event2 = MetricsEvent . new ( @feature2 , @target , @variation2 , Logger . new ( STDOUT ) )
477
-
478
- assert ( event1 != event2 )
479
- end
480
428
481
429
def test_metrics_processor_prevents_invalid_metrics_event
482
430
logger = Logger . new ( STDOUT )
@@ -495,15 +443,15 @@ def test_metrics_processor_prevents_invalid_metrics_event
495
443
callback . wait_until_ready
496
444
497
445
# Attempt to register invalid evaluations
498
- metrics_processor . register_evaluation ( @target , nil , @variation1 )
446
+ metrics_processor . register_evaluation ( @target , nil , @variation1 . identifier )
499
447
metrics_processor . register_evaluation ( @target , nil , nil )
500
- metrics_processor . register_evaluation ( nil , @feature1 , nil )
448
+ metrics_processor . register_evaluation ( nil , @feature1 . feature , nil )
501
449
502
450
# Register some valid evaluations
503
- metrics_processor . register_evaluation ( @target , @feature1 , @variation1 )
504
- metrics_processor . register_evaluation ( @target , @feature2 , @variation2 )
451
+ metrics_processor . register_evaluation ( @target , @feature1 . feature , @variation1 . identifier )
452
+ metrics_processor . register_evaluation ( @target , @feature2 . feature , @variation2 . identifier )
505
453
# Nil target, which is a valid input to variation methods
506
- metrics_processor . register_evaluation ( nil , @feature2 , @variation2 )
454
+ metrics_processor . register_evaluation ( nil , @feature2 . feature , @variation2 . identifier )
507
455
508
456
# Run iteration
509
457
metrics_processor . send ( :run_one_iteration )
@@ -535,11 +483,4 @@ def test_metrics_processor_prevents_invalid_metrics_event
535
483
assert_equal 1 , captured_metrics [ 0 ] . target_data . size , "There should only be a single target"
536
484
end
537
485
538
- def test_metrics_event_eql_with_invalid_object
539
- event = MetricsEvent . new ( @feature1 , @target , @variation1 , Logger . new ( STDOUT ) )
540
- non_event = "Not a MetricsEvent"
541
-
542
- refute_equal ( event , non_event , "MetricsEvent should not be equal to a non-MetricsEvent object" )
543
- end
544
-
545
486
end
0 commit comments