Skip to content

Commit 0029030

Browse files
author
Pedro Crespo
committed
Fixes test failure in director by keeping same loop
Removed pytest.mark.asyncio decorators. no need with pytest-aiohttp
1 parent ad55d3d commit 0029030

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

services/director/tests/test_handlers.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
API_VERSIONS = resources.listdir(resources.RESOURCE_OPENAPI_ROOT)
1111

12-
@pytest.mark.asyncio
12+
1313
async def test_root_get():
1414
fake_request = "fake request"
1515
web_response = await rest.handlers.root_get(fake_request)
16-
assert web_response.content_type == "application/json"
16+
assert web_response.content_type == "application/json"
1717
assert web_response.status == 200
1818
healthcheck_enveloped = json.loads(web_response.text)
1919
assert "data" in healthcheck_enveloped
@@ -30,29 +30,29 @@ def _check_services(created_services, services, schema_version="v1"):
3030
assert len(created_services) == len(services)
3131

3232
created_service_descriptions = [x["service_description"] for x in created_services]
33-
33+
3434
json_schema_path = resources.get_path(resources.RESOURCE_NODE_SCHEMA)
3535
assert json_schema_path.exists() == True
3636
with json_schema_path.open() as file_pt:
3737
service_schema = json.load(file_pt)
3838

39-
for service in services:
39+
for service in services:
4040
if schema_version == "v1":
4141
assert created_service_descriptions.count(service) == 1
4242
json_schema_validator.validate_instance_object(service, service_schema)
4343

44-
@pytest.mark.asyncio
44+
4545
async def test_services_get(docker_registry, push_services):
4646
fake_request = "fake request"
4747
# no registry defined
4848
with pytest.raises(web_exceptions.HTTPInternalServerError, message="Expecting HTTP Internal Error as no registry URL is defined"):
4949
services_enveloped = await rest.handlers.services_get(fake_request)
5050

5151
# wrong registry defined
52-
config.REGISTRY_URL = "blahblah"
52+
config.REGISTRY_URL = "blahblah"
5353
with pytest.raises(web_exceptions.HTTPInternalServerError, message="Expecting HTTP Internal Error as SSL is enabled by default"):
5454
services_enveloped = await rest.handlers.services_get(fake_request)
55-
55+
5656
# right registry defined
5757
config.REGISTRY_URL = docker_registry
5858
with pytest.raises(web_exceptions.HTTPInternalServerError, message="Expecting HTTP Internal Error as SSL is enabled by default"):
@@ -103,7 +103,7 @@ async def test_services_get(docker_registry, push_services):
103103
services = services_enveloped["data"]
104104
assert len(services) == 2
105105

106-
@pytest.mark.asyncio
106+
107107
async def test_v0_services_conversion_to_new(configure_registry_access, push_v0_schema_services): #pylint: disable=W0613, W0621
108108
fake_request = "fake request"
109109
created_services = push_v0_schema_services(3,2)
@@ -117,7 +117,7 @@ async def test_v0_services_conversion_to_new(configure_registry_access, push_v0_
117117
# ensure old style services are not retrieved
118118
assert len(services) == 0
119119

120-
@pytest.mark.asyncio
120+
121121
async def test_services_by_key_version_get(configure_registry_access, push_services): #pylint: disable=W0613, W0621
122122
fake_request = "fake request"
123123

@@ -131,7 +131,7 @@ async def test_services_by_key_version_get(configure_registry_access, push_servi
131131
web_response = await rest.handlers.services_by_key_version_get(fake_request, "whatever", "ofwhateverversion")
132132

133133
created_services = push_services(3,2)
134-
assert len(created_services) == 5
134+
assert len(created_services) == 5
135135

136136
retrieved_services = []
137137
for created_service in created_services:
@@ -151,19 +151,19 @@ async def _start_get_stop_services(push_services, user_id):
151151

152152
with pytest.raises(web_exceptions.HTTPInternalServerError, message="Expecting internal server error"):
153153
web_response = await rest.handlers.running_interactive_services_post(fake_request, None, None, None, None)
154-
154+
155155
with pytest.raises(web_exceptions.HTTPInternalServerError, message="Expecting internal server error"):
156156
web_response = await rest.handlers.running_interactive_services_post(fake_request, "None", None, None, None)
157157

158158
with pytest.raises(web_exceptions.HTTPInternalServerError, message="Expecting internal server error"):
159159
web_response = await rest.handlers.running_interactive_services_post(fake_request, "None", "None", None, None)
160-
160+
161161
with pytest.raises(web_exceptions.HTTPNotFound, message="Expecting not found error"):
162162
web_response = await rest.handlers.running_interactive_services_post(fake_request, "None", "None", "None", None)
163163

164164
with pytest.raises(web_exceptions.HTTPNotFound, message="Expecting not found error"):
165165
web_response = await rest.handlers.running_interactive_services_post(fake_request, "None", "None", "None", "ablah")
166-
166+
167167
with pytest.raises(web_exceptions.HTTPInternalServerError, message="Expecting internal server error"):
168168
web_response = await rest.handlers.running_interactive_services_get(fake_request, None)
169169

@@ -201,11 +201,11 @@ async def _start_get_stop_services(push_services, user_id):
201201
assert web_response.content_type == "application/json"
202202
assert web_response.text is None
203203

204-
@pytest.mark.asyncio
204+
205205
async def test_running_services_post_and_delete_no_swarm(configure_registry_access, push_services, user_id): #pylint: disable=W0613, W0621
206206
with pytest.raises(web_exceptions.HTTPInternalServerError, message="Expecting internal error as there is no docker swarm"):
207207
await _start_get_stop_services(push_services, user_id)
208208

209-
@pytest.mark.asyncio
209+
210210
async def test_running_services_post_and_delete(configure_registry_access, push_services, docker_swarm, user_id): #pylint: disable=W0613, W0621
211211
await _start_get_stop_services(push_services, user_id)

services/director/tests/test_producer.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
)
99

1010
@pytest.fixture
11-
async def run_services(configure_registry_access, push_services, docker_swarm, user_id): #pylint: disable=W0613, W0621
11+
async def run_services(loop, configure_registry_access, push_services, docker_swarm, user_id): #pylint: disable=W0613, W0621
1212
started_services = []
1313
async def push_start_services(number_comp, number_dyn):
1414
pushed_services = push_services(number_comp,number_dyn, 60)
1515
assert len(pushed_services) == (number_comp + number_dyn)
16-
for pushed_service in pushed_services:
16+
for pushed_service in pushed_services:
1717
service_description = pushed_service["service_description"]
1818

1919
service_key = service_description["key"]
@@ -25,26 +25,27 @@ async def push_start_services(number_comp, number_dyn):
2525
started_service = await producer.start_service(user_id, service_key, service_version, service_uuid)
2626
assert "published_port" in started_service
2727
assert "entry_point" in started_service
28-
assert "service_uuid" in started_service
28+
assert "service_uuid" in started_service
2929
# should not throw
3030
await producer.get_service_details(service_uuid)
3131
started_services.append(started_service)
3232
return started_services
33+
3334
yield push_start_services
3435

3536
#teardown stop the services
36-
for service in started_services:
37+
for service in started_services:
3738
service_uuid = service["service_uuid"]
3839
await producer.stop_service(service_uuid)
3940
with pytest.raises(exceptions.ServiceUUIDNotFoundError, message="expecting service uuid not found error"):
4041
await producer.get_service_details(service_uuid)
4142

42-
@pytest.mark.asyncio
43+
4344
async def test_start_stop_service(run_services): #pylint: disable=W0613, W0621
4445
# standard test
4546
await run_services(1,1)
4647

47-
@pytest.mark.asyncio
48+
4849
async def test_service_assigned_env_variables(run_services, user_id): #pylint: disable=W0621
4950
started_services = await run_services(1,1)
5051
client = docker.from_env()
@@ -70,7 +71,7 @@ async def test_service_assigned_env_variables(run_services, user_id): #pylint: d
7071
assert "SIMCORE_USER_ID" in envs_dict
7172
assert envs_dict["SIMCORE_USER_ID"] == user_id
7273

73-
@pytest.mark.asyncio
74+
7475
async def test_interactive_service_published_port(run_services): #pylint: disable=W0621
7576
running_dynamic_services = await run_services(0,1)
7677
assert len(running_dynamic_services) == 1
@@ -88,4 +89,4 @@ async def test_interactive_service_published_port(run_services): #pylint: disabl
8889
low_level_client = docker.APIClient()
8990
service_information = low_level_client.inspect_service(docker_service.id)
9091
service_published_port = service_information["Endpoint"]["Ports"][0]["PublishedPort"]
91-
assert service_published_port == service_port
92+
assert service_published_port == service_port

0 commit comments

Comments
 (0)