@@ -116,30 +116,6 @@ def test_has_subscription(subscription_controller, subscriptions_config, channel
116116 assert result is expected
117117
118118
119- @pytest .mark .parametrize ("retries,timeout,expected_retries,expected_timeout" , [
120- (None , None , DEFAULT_SUBSCRIPTION_RETRIES , DEFAULT_SUBSCRIPTION_TIMEOUT ), # defaults
121- (10 , 5.0 , 10 , 5.0 ), # custom values
122- (0 , 1.0 , 0 , 1.0 ), # zero retries
123- ])
124- def test_init_parameters (mock_processor , retries , timeout , expected_retries , expected_timeout ):
125- # Arrange
126- kwargs = {}
127- if retries is not None :
128- kwargs ['subscription_retries' ] = retries
129- if timeout is not None :
130- kwargs ['subscription_timeout' ] = timeout
131-
132- # Act
133- controller = SubscriptionController (subscription_processor = mock_processor , ** kwargs )
134-
135- # Assert
136- assert controller ._subscription_processor == mock_processor
137- assert controller ._subscription_retries == expected_retries
138- assert controller ._subscription_timeout == expected_timeout
139- assert controller ._subscriptions == {}
140- assert controller ._operational_lock is not None
141-
142-
143119@pytest .mark .parametrize ("modifications,expected_status,expected_data,expected_confirmation,expected_processor_is_new" , [
144120 # Status only
145121 ({'status' : True }, True , {'original' : 'data' }, True , False ),
@@ -434,79 +410,3 @@ def controller_with_mixed_subscriptions():
434410 return controller
435411
436412
437- def test_recreate_subscriptions_thread_safety_with_lock (controller_with_mixed_subscriptions , monkeypatch ):
438- # Arrange
439- lock_acquired = []
440- original_acquire = controller_with_mixed_subscriptions ._operational_lock .acquire
441- original_release = controller_with_mixed_subscriptions ._operational_lock .release
442-
443- def track_acquire (* args , ** kwargs ):
444- lock_acquired .append ('acquire' )
445- return original_acquire (* args , ** kwargs )
446-
447- def track_release (* args , ** kwargs ):
448- lock_acquired .append ('release' )
449- return original_release (* args , ** kwargs )
450-
451- monkeypatch .setattr (controller_with_mixed_subscriptions ._operational_lock , 'acquire' , track_acquire )
452- monkeypatch .setattr (controller_with_mixed_subscriptions ._operational_lock , 'release' , track_release )
453-
454- # Mock subscribe method
455- mock_subscribe = MagicMock (return_value = True )
456- monkeypatch .setattr (controller_with_mixed_subscriptions , 'subscribe' , mock_subscribe )
457-
458- # Act
459- controller_with_mixed_subscriptions .recreate_subscriptions ()
460-
461- # Assert
462- # Lock should have been acquired and released
463- assert 'acquire' in lock_acquired
464- assert 'release' in lock_acquired
465- # Should be balanced (acquire followed by release)
466- assert lock_acquired .count ('acquire' ) == lock_acquired .count ('release' )
467-
468-
469- def test_recreate_subscriptions_logging_behavior (subscription_controller , monkeypatch , caplog ):
470- # Arrange
471- import logging
472- caplog .set_level (logging .INFO )
473-
474- subscription_controller ._subscriptions = {
475- 'inactive_channel_1' : {
476- 'status' : False ,
477- 'data' : {'key' : 'value1' },
478- 'needs_confirmation' : True ,
479- 'subscription_processor' : MagicMock ()
480- },
481- 'inactive_channel_2' : {
482- 'status' : False ,
483- 'data' : {'key' : 'value2' },
484- 'needs_confirmation' : False ,
485- 'subscription_processor' : None
486- }
487- }
488-
489- # Mock subscribe to succeed for one, fail for another
490- def mock_subscribe_side_effect (channel , * args , ** kwargs ):
491- return channel == 'inactive_channel_1'
492-
493- mock_subscribe = MagicMock (side_effect = mock_subscribe_side_effect )
494- monkeypatch .setattr (subscription_controller , 'subscribe' , mock_subscribe )
495-
496- # Act
497- subscription_controller .recreate_subscriptions ()
498-
499- # Assert
500- # Should log info about recreation attempt
501- info_logs = [record for record in caplog .records if record .levelname == 'INFO' ]
502- assert len (info_logs ) > 0
503- info_message = info_logs [0 ].message
504- assert 'Recreating' in info_message
505- assert '2/2 subscriptions' in info_message
506-
507- # Should log error about failed subscriptions
508- error_logs = [record for record in caplog .records if record .levelname == 'ERROR' ]
509- assert len (error_logs ) > 0
510- error_message = error_logs [0 ].message
511- assert 'Failed to re-subscribe' in error_message
512- assert '1 channels' in error_message
0 commit comments