Skip to content

Commit 6477862

Browse files
committed
try to fix flaky appveyor tests (#259)
test_urllib3 is quite flaky on appveyor. The assumption is that due to the slow executor machine, the http server used in this test isn't quick enough to boot up. Now we wait for the server to boot up. closes #259 Signed-off-by: Benjamin Wohlwend <[email protected]>
1 parent 1bcc94c commit 6477862

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from os.path import abspath, dirname, join
44

55
from tests.fixtures import (elasticapm_client, instrument, not_so_random,
6-
sending_elasticapm_client, validating_httpserver)
6+
sending_elasticapm_client, validating_httpserver,
7+
waiting_httpserver)
78
from tests.utils.compat import middleware_setting
89

910
try:

tests/fixtures.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import json
33
import os
44
import random
5+
import socket
6+
import time
57
import zlib
68

79
import jsonschema
@@ -94,10 +96,17 @@ def elasticapm_client(request):
9496
client.close()
9597

9698

99+
@pytest.fixture()
100+
def waiting_httpserver(httpserver):
101+
wait_for_http_server(httpserver)
102+
return httpserver
103+
104+
97105
@pytest.fixture()
98106
def validating_httpserver(request):
99107
server = ValidatingWSGIApp()
100108
server.start()
109+
wait_for_http_server(server)
101110
request.addfinalizer(server.stop)
102111
return server
103112

@@ -140,3 +149,15 @@ def instrument():
140149
elasticapm.instrument()
141150
yield
142151
elasticapm.uninstrument()
152+
153+
154+
def wait_for_http_server(httpserver, timeout=30):
155+
start_time = time.time()
156+
while True:
157+
try:
158+
sock = socket.create_connection(httpserver.server_address, timeout=0.1)
159+
sock.close()
160+
break
161+
except socket.error:
162+
if time.time() - start_time > timeout:
163+
raise TimeoutError()

tests/instrumentation/urllib3_tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77

88
@mock.patch("elasticapm.traces.TransactionsStore.should_collect")
9-
def test_urllib3(should_collect, instrument, elasticapm_client, httpserver):
9+
def test_urllib3(should_collect, instrument, elasticapm_client, waiting_httpserver):
1010
should_collect.return_value = False
11-
httpserver.serve_content('')
12-
url = httpserver.url + '/hello_world'
11+
waiting_httpserver.serve_content('')
12+
url = waiting_httpserver.url + '/hello_world'
1313
parsed_url = urlparse.urlparse(url)
1414
elasticapm_client.begin_transaction("transaction")
1515
expected_sig = 'GET {0}'.format(parsed_url.netloc)

0 commit comments

Comments
 (0)