Example #1
0
    def test_concurrency_set(self, Popen, cpu_count):
        """
        Test for the case where PULP_CONCURRENCY is set in /etc/default/pulp_workers.
        """
        class MockPipe(object):
            def communicate(self):
                """
                Return 32\n as the output of the subprocess, to simulate PULP_CONCURRENCY being
                defined as 32.
                """
                return ('32\n', )

        Popen.return_value = MockPipe()

        concurrency = manage_workers._get_concurrency()

        # Since we mocked the output of the subprocess call to be 32\n, concurrency should be 32
        self.assertEqual(concurrency, 32)
        # Make sure that Popen was called correctly
        Popen.assert_called_once_with('. %s; echo $PULP_CONCURRENCY' %
                                      manage_workers._ENVIRONMENT_FILE,
                                      stdout=subprocess.PIPE,
                                      shell=True)
        # Since the shell call was successful, no call to cpu_count() should have been made
        self.assertEqual(cpu_count.call_count, 0)
Example #2
0
    def test_concurrency_not_set(self, Popen, cpu_count):
        """
        Test for the case where PULP_CONCURRENCY is not set in /etc/default/pulp_workers.
        """
        class MockPipe(object):
            def communicate(self):
                """
                Return \n as the output of the subprocess, to simulate PULP_CONCURRENCY not being
                defined.
                """
                return ('\n',)
        Popen.return_value = MockPipe()

        concurrency = manage_workers._get_concurrency()

        # Since we mocked the cpu_count to be 16, concurrency should be 16
        self.assertEqual(concurrency, 16)
        # Make sure that Popen and cpu_count were called correctly
        Popen.assert_called_once_with(
            '. %s; echo $PULP_CONCURRENCY' % manage_workers._ENVIRONMENT_FILE,
            stdout=subprocess.PIPE, shell=True)
        cpu_count.assert_called_once_with()
Example #3
0
    def test_concurrency_set(self, Popen, cpu_count):
        """
        Test for the case where PULP_CONCURRENCY is set in /etc/default/pulp_workers.
        """
        class MockPipe(object):
            def communicate(self):
                """
                Return 32\n as the output of the subprocess, to simulate PULP_CONCURRENCY being
                defined as 32.
                """
                return ('32\n',)
        Popen.return_value = MockPipe()

        concurrency = manage_workers._get_concurrency()

        # Since we mocked the output of the subprocess call to be 32\n, concurrency should be 32
        self.assertEqual(concurrency, 32)
        # Make sure that Popen was called correctly
        Popen.assert_called_once_with(
            '. %s; echo $PULP_CONCURRENCY' % manage_workers._ENVIRONMENT_FILE,
            stdout=subprocess.PIPE, shell=True)
        # Since the shell call was successful, no call to cpu_count() should have been made
        self.assertEqual(cpu_count.call_count, 0)
Example #4
0
    def test_concurrency_not_set(self, Popen, cpu_count):
        """
        Test for the case where PULP_CONCURRENCY is not set in /etc/default/pulp_workers.
        """
        class MockPipe(object):
            def communicate(self):
                """
                Return \n as the output of the subprocess, to simulate PULP_CONCURRENCY not being
                defined.
                """
                return ('\n', )

        Popen.return_value = MockPipe()

        concurrency = manage_workers._get_concurrency()

        # Since we mocked the cpu_count to be 16, concurrency should be 16
        self.assertEqual(concurrency, 16)
        # Make sure that Popen and cpu_count were called correctly
        Popen.assert_called_once_with('. %s; echo $PULP_CONCURRENCY' %
                                      manage_workers._ENVIRONMENT_FILE,
                                      stdout=subprocess.PIPE,
                                      shell=True)
        cpu_count.assert_called_once_with()