Browse Source

Use a condition variable instead of sleeping

pull/1208/head
Armin Ronacher 11 years ago
parent
commit
75f2af7a6a
  1. 9
      flask/testsuite/basic.py

9
flask/testsuite/basic.py

@ -15,8 +15,7 @@ import flask
import pickle import pickle
import unittest import unittest
from datetime import datetime from datetime import datetime
from threading import Thread from threading import Thread, Condition
from time import sleep
from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning
from flask._compat import text_type from flask._compat import text_type
from werkzeug.exceptions import BadRequest, NotFound from werkzeug.exceptions import BadRequest, NotFound
@ -1019,12 +1018,16 @@ class BasicFunctionalityTestCase(FlaskTestCase):
def test_before_first_request_functions_concurrent(self): def test_before_first_request_functions_concurrent(self):
got = [] got = []
app = flask.Flask(__name__) app = flask.Flask(__name__)
cv = Condition()
@app.before_first_request @app.before_first_request
def foo(): def foo():
sleep(1) with cv:
cv.wait()
got.append(42) got.append(42)
c = app.test_client() c = app.test_client()
def get_and_assert(): def get_and_assert():
with cv:
cv.notify()
c.get("/") c.get("/")
self.assert_equal(got, [42]) self.assert_equal(got, [42])
t = Thread(target=get_and_assert) t = Thread(target=get_and_assert)

Loading…
Cancel
Save