@@ -121,11 +121,6 @@ def test_standalone_optimized(self, mocker):
121121 assert imps == [Impression ('k1' , 'f1' , 'on' , 'l1' , 123 , None , utc_now - 3 ),
122122 Impression ('k1' , 'f2' , 'on' , 'l1' , 123 , None , utc_now - 3 )]
123123
124- assert [Counter .CountPerFeature (k .feature , k .timeframe , v )
125- for (k , v ) in manager ._strategy ._counter ._data .items ()] == [
126- Counter .CountPerFeature ('f1' , truncate_time (utc_now - 3 ), 1 ),
127- Counter .CountPerFeature ('f2' , truncate_time (utc_now - 3 ), 1 )]
128-
129124 # Tracking the same impression a ms later should be empty
130125 imps = manager .process_impressions ([
131126 (Impression ('k1' , 'f1' , 'on' , 'l1' , 123 , None , utc_now - 2 ), None )
@@ -154,14 +149,26 @@ def test_standalone_optimized(self, mocker):
154149 Impression ('k2' , 'f1' , 'on' , 'l1' , 123 , None , utc_now - 2 , old_utc - 1 )]
155150
156151 assert len (manager ._strategy ._observer ._cache ._data ) == 3 # distinct impressions seen
157- assert len (manager ._strategy ._counter ._data ) == 3 # 2 distinct features. 1 seen in 2 different timeframes
152+ assert len (manager ._strategy ._counter ._data ) == 2 # 2 distinct features. 1 seen in 2 different timeframes
158153
159154 assert set (manager ._strategy ._counter .pop_all ()) == set ([
160- Counter .CountPerFeature ('f1' , truncate_time (old_utc ), 3 ),
161- Counter .CountPerFeature ('f2' , truncate_time (old_utc ), 1 ),
155+ Counter .CountPerFeature ('f1' , truncate_time (old_utc ), 1 ),
162156 Counter .CountPerFeature ('f1' , truncate_time (utc_now ), 2 )
163157 ])
164158
159+ # Test counting only from the second impression
160+ imps = manager .process_impressions ([
161+ (Impression ('k3' , 'f3' , 'on' , 'l1' , 123 , None , utc_now - 1 ), None )
162+ ])
163+ assert set (manager ._strategy ._counter .pop_all ()) == set ([])
164+
165+ imps = manager .process_impressions ([
166+ (Impression ('k3' , 'f3' , 'on' , 'l1' , 123 , None , utc_now - 1 ), None )
167+ ])
168+ assert set (manager ._strategy ._counter .pop_all ()) == set ([
169+ Counter .CountPerFeature ('f3' , truncate_time (utc_now ), 1 )
170+ ])
171+
165172 def test_standalone_debug (self , mocker ):
166173 """Test impressions manager in debug mode with sdk in standalone mode."""
167174
@@ -304,10 +311,6 @@ def test_standalone_optimized_listener(self, mocker):
304311 ])
305312 assert imps == [Impression ('k1' , 'f1' , 'on' , 'l1' , 123 , None , utc_now - 3 ),
306313 Impression ('k1' , 'f2' , 'on' , 'l1' , 123 , None , utc_now - 3 )]
307- assert [Counter .CountPerFeature (k .feature , k .timeframe , v )
308- for (k , v ) in manager ._strategy ._counter ._data .items ()] == [
309- Counter .CountPerFeature ('f1' , truncate_time (utc_now - 3 ), 1 ),
310- Counter .CountPerFeature ('f2' , truncate_time (utc_now - 3 ), 1 )]
311314
312315 # Tracking the same impression a ms later should return empty
313316 imps = manager .process_impressions ([
@@ -336,11 +339,10 @@ def test_standalone_optimized_listener(self, mocker):
336339 Impression ('k2' , 'f1' , 'on' , 'l1' , 123 , None , utc_now - 2 , old_utc - 1 )]
337340
338341 assert len (manager ._strategy ._observer ._cache ._data ) == 3 # distinct impressions seen
339- assert len (manager ._strategy ._counter ._data ) == 3 # 2 distinct features. 1 seen in 2 different timeframes
342+ assert len (manager ._strategy ._counter ._data ) == 2 # 2 distinct features. 1 seen in 2 different timeframes
340343
341344 assert set (manager ._strategy ._counter .pop_all ()) == set ([
342- Counter .CountPerFeature ('f1' , truncate_time (old_utc ), 3 ),
343- Counter .CountPerFeature ('f2' , truncate_time (old_utc ), 1 ),
345+ Counter .CountPerFeature ('f1' , truncate_time (old_utc ), 1 ),
344346 Counter .CountPerFeature ('f1' , truncate_time (utc_now ), 2 )
345347 ])
346348
@@ -353,6 +355,19 @@ def test_standalone_optimized_listener(self, mocker):
353355 mocker .call (Impression ('k2' , 'f1' , 'on' , 'l1' , 123 , None , utc_now - 2 , old_utc - 1 ), None )
354356 ]
355357
358+ # Test counting only from the second impression
359+ imps = manager .process_impressions ([
360+ (Impression ('k3' , 'f3' , 'on' , 'l1' , 123 , None , utc_now - 1 ), None )
361+ ])
362+ assert set (manager ._strategy ._counter .pop_all ()) == set ([])
363+
364+ imps = manager .process_impressions ([
365+ (Impression ('k3' , 'f3' , 'on' , 'l1' , 123 , None , utc_now - 1 ), None )
366+ ])
367+ assert set (manager ._strategy ._counter .pop_all ()) == set ([
368+ Counter .CountPerFeature ('f3' , truncate_time (utc_now ), 1 )
369+ ])
370+
356371 def test_standalone_debug_listener (self , mocker ):
357372 """Test impressions manager in optimized mode with sdk in standalone mode."""
358373
0 commit comments