2688
2689
{'notifications': 'True'})
2690
2691
@patch.object(context, 'psutil')
2691
def test_workerconfig_context_xenial(self, _psutil):
2692
self.config.side_effect = fake_config({
2693
'worker-multiplier': 1,
2692
def test_num_cpus_xenial(self, _psutil):
2695
2693
_psutil.cpu_count.return_value = 4
2696
worker = context.WorkerConfigContext()
2697
self.assertTrue(worker.num_cpus, 4)
2694
self.assertTrue(context._num_cpus(), 4)
2699
2696
@patch.object(context, 'psutil')
2700
def test_workerconfig_context_trusty(self, _psutil):
2701
self.config.side_effect = fake_config({
2702
'worker-multiplier': 2,
2697
def test_num_cpus_trusty(self, _psutil):
2704
2698
_psutil.NUM_CPUS = 4
2705
worker = context.WorkerConfigContext()
2706
self.assertTrue(worker.num_cpus, 2)
2699
self.assertTrue(context._num_cpus(), 4)
2708
def test_workerconfig_context_float(self):
2701
@patch.object(context, '_num_cpus')
2702
def test_calculate_workers_float(self, _num_cpus):
2709
2703
self.config.side_effect = fake_config({
2710
2704
'worker-multiplier': 0.3
2712
with patch.object(context.WorkerConfigContext, 'num_cpus', 4):
2713
worker = context.WorkerConfigContext()
2714
self.assertTrue(worker.num_cpus, 1)
2706
_num_cpus.return_value = 4
2707
self.assertTrue(context._calculate_workers(), 4)
2716
def test_workerconfig_context_not_quite_0(self):
2709
@patch.object(context, '_num_cpus')
2710
def test_calculate_workers_not_quite_0(self, _num_cpus):
2717
2711
# Make sure that the multiplier evaluating to somewhere between
2718
2712
# 0 and 1 in the floating point range still has at least one
2720
2714
self.config.side_effect = fake_config({
2721
2715
'worker-multiplier': 0.001
2723
with patch.object(context.WorkerConfigContext, 'num_cpus', 100):
2724
worker = context.WorkerConfigContext()
2725
self.assertTrue(worker.num_cpus, 1)
2717
_num_cpus.return_value = 100
2718
self.assertTrue(context._calculate_workers(), 1)
2727
def test_workerconfig_context_0(self):
2720
@patch.object(context, 'psutil')
2721
def test_calculate_workers_0(self, _psutil):
2728
2722
self.config.side_effect = fake_config({
2729
2723
'worker-multiplier': 0
2731
with patch.object(context.WorkerConfigContext, 'num_cpus', 2):
2732
worker = context.WorkerConfigContext()
2733
self.assertTrue(worker.num_cpus, 0)
2735
def test_workerconfig_context_noconfig(self):
2736
self.config.return_value = None
2737
with patch.object(context.WorkerConfigContext, 'num_cpus', 1):
2738
worker = context.WorkerConfigContext()
2739
self.assertEqual({'workers': 2}, worker())
2741
def test_workerconfig_context_noconfig_container(self):
2742
self.config.return_value = None
2743
self.is_container.return_value = True
2744
with patch.object(context.WorkerConfigContext, 'num_cpus', 1):
2745
worker = context.WorkerConfigContext()
2746
self.assertEqual({'workers': 2}, worker())
2748
def test_workerconfig_context_noconfig_lotsa_cpus_container(self):
2749
self.config.return_value = None
2750
self.is_container.return_value = True
2751
with patch.object(context.WorkerConfigContext, 'num_cpus', 32):
2752
worker = context.WorkerConfigContext()
2753
self.assertEqual({'workers': 4}, worker())
2755
def test_workerconfig_context_noconfig_lotsa_cpus_not_container(self):
2756
self.config.return_value = None
2757
with patch.object(context.WorkerConfigContext, 'num_cpus', 32):
2758
worker = context.WorkerConfigContext()
2759
self.assertEqual({'workers': 64}, worker())
2761
def test_workerconfig_context_withconfig(self):
2762
self.config.side_effect = fake_config({
2763
'worker-multiplier': 4,
2765
with patch.object(context.WorkerConfigContext, 'num_cpus', 2):
2766
worker = context.WorkerConfigContext()
2767
self.assertEqual({'workers': 8}, worker())
2725
_psutil.cpu_count.return_value = 2
2726
self.assertTrue(context._calculate_workers(), 0)
2728
@patch.object(context, '_num_cpus')
2729
def test_calculate_workers_noconfig(self, _num_cpus):
2730
self.config.return_value = None
2731
_num_cpus.return_value = 1
2732
self.assertTrue(context._calculate_workers(), 2)
2734
@patch.object(context, '_num_cpus')
2735
def test_calculate_workers_noconfig_container(self, _num_cpus):
2736
self.config.return_value = None
2737
self.is_container.return_value = True
2738
_num_cpus.return_value = 1
2739
self.assertTrue(context._calculate_workers(), 2)
2741
@patch.object(context, '_num_cpus')
2742
def test_calculate_workers_noconfig_lotsa_cpus_container(self,
2744
self.config.return_value = None
2745
self.is_container.return_value = True
2746
_num_cpus.return_value = 32
2747
self.assertTrue(context._calculate_workers(), 4)
2749
@patch.object(context, '_num_cpus')
2750
def test_calculate_workers_noconfig_lotsa_cpus_not_container(self,
2752
self.config.return_value = None
2753
_num_cpus.return_value = 32
2754
self.assertTrue(context._calculate_workers(), 64)
2756
@patch.object(context, '_calculate_workers', return_value=256)
2757
def test_worker_context(self, calculate_workers):
2758
self.assertEqual(context.WorkerConfigContext()(),
2769
2761
def test_apache_get_addresses_no_network_splits(self):
2770
2762
self.https.return_value = True