1 # ============LICENSE_START===================================================
2 # Copyright (C) 2020 Nordix Foundation.
3 # ============================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # SPDX-License-Identifier: Apache-2.0
17 # ============LICENSE_END=====================================================
19 from signal import SIGTERM, signal
20 from unittest.mock import patch, Mock
22 from mod.exit_handler import ExitHandler
23 from mod.subscription import Subscription
24 from tests.base_setup import BaseClassSetup
27 class ExitHandlerTests(BaseClassSetup):
33 @patch('mod.pmsh_utils.PeriodicTask')
34 def setUp(self, mock_periodic_task):
36 self.mock_aai_event_thread = mock_periodic_task
37 self.sub = self.app_conf.subscription
43 def tearDownClass(cls):
44 super().tearDownClass()
46 @patch.object(Subscription, 'update_sub_nf_status')
47 @patch.object(Subscription, 'update_subscription_status')
48 def test_terminate_signal_successful(self, mock_upd_sub_status,
49 mock_upd_subnf_status):
50 handler = ExitHandler(periodic_tasks=[self.mock_aai_event_thread],
51 app_conf=self.app_conf,
52 subscription_handler=Mock())
53 signal(SIGTERM, handler)
54 os.kill(os.getpid(), SIGTERM)
55 self.assertTrue(ExitHandler.shutdown_signal_received)