def test_run():
    rail_gun = Railgun(semaphores_count=5, loop=get_event_loop())
    results = rail_gun.run(
        [example_method_one(1, 2),
         example_method_one(1, 2)])
    assert len(results) == 2
    assert results[0] == 3
def test_run_async():
    loop = get_event_loop()
    rail_gun = Railgun(semaphores_count=5, loop=loop)
    results = rail_gun.run_async(
        [example_method_one(1, 2),
         example_method_one(1, 2)])
    results = loop.run_until_complete(results)
    assert len(results) == 2
    assert results[0] == 3
Exemple #3
0
 def test_fire_exception(self, mock_logger):
     test_exception = "test exception"
     mock_write = MagicMock(side_effect=ValueError(test_exception))
     with patch("railgun.engines.storage_engine.DummyEngine.write", mock_write):
         r = Railgun(self.config["test"])
         self.assertRaises(RailgunException, r.fire, "test")
         try:
             r.fire("test")
         except RailgunException:
             self.assertTrue(mock_logger.critical.called)
Exemple #4
0
    def test_add_engine_valid_config(self):
        r = Railgun(self.config["test"])

        alt_config = self.config["test"]
        alt_config["engine_config"] = {"field1": "value_3", "field2": "value_4"}

        e = r._add_engine(alt_config)

        self.assertEqual(
            [e.field1, e.field2], [alt_config["engine_config"]["field1"], alt_config["engine_config"]["field2"]]
        )
def test_repeat_api_call():
    rail_gun = Railgun(semaphores_count=5, loop=get_event_loop())
    results = rail_gun.repeat(example_call_api, ['www.google.com', '/'],
                              repeat=5)
    assert len(results) == 5
    assert results[0] == 200
def test_run_api_call():
    rail_gun = Railgun(semaphores_count=5, loop=get_event_loop())
    results = rail_gun.run([example_call_api(), example_call_api()])
    assert len(results) == 2
    assert results[0] == 200
def test_repeat():
    rail_gun = Railgun(semaphores_count=5, loop=get_event_loop())
    repeats = rail_gun.repeat(example_method_one, [1, 2], repeat=10)

    assert len(repeats) == 10
    assert repeats[0] == 3
Exemple #8
0
 def test_fire(self):
     test_data = "test data"
     with patch("railgun.engines.storage_engine.DummyEngine.write") as mock_write:
         r = Railgun(self.config["test"])
         r.fire(test_data)
         mock_write.assert_called_once_with(test_data)
Exemple #9
0
 def test_assess(self):
     test_id = "test id"
     with patch("railgun.engines.storage_engine.DummyEngine.result") as mock_result:
         r = Railgun(self.config["test"])
         r.assess(test_id)
         mock_result.assert_called_once_with(test_id)
Exemple #10
0
 def test_track(self):
     test_id = "test id"
     with patch("railgun.engines.storage_engine.DummyEngine.ready") as mock_track:
         r = Railgun(self.config["test"])
         r.track(test_id)
         mock_track.assert_called_once_with(test_id)
Exemple #11
0
def call_web(url='http://www.google.com'):
    return requests.get(url=url).status_code


async def call_web_async(url='http://www.google.com'):
    status_code = requests.get(url=url).status_code
    print(status_code)
    await asyncio.sleep(0.1)
    return status_code


# tasks = [random_task(5,10), random_task(1,1), random_task(2,5), random_task_async(6,3)]

tasks = [call_web()] * 100
print('before railgun')
rail_gun = Railgun(semaphores_count=500)
# time.sleep(3)
print('After rail gun')
# test = rail_gun.run(tasks)
print('After rail gun run')

# print(test)
# print(f'len of returns {len(test)}')
loop = asyncio.get_event_loop()
async_tasks_1 = []
async_tasks_2 = []
start = time.time()
# for x in range(0, 299):
#     async_tasks_1.append(call_web_async())
#     async_tasks_2.append(call_web_async())
print(f'after for loop: {time.time() - start}')