From 75f2af7a6afdf620d7afdccee876b06f8c39373b Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 9 Feb 2014 13:25:36 +0000 Subject: [PATCH] Use a condition variable instead of sleeping --- flask/testsuite/basic.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/flask/testsuite/basic.py b/flask/testsuite/basic.py index 8399a607..4da4c549 100644 --- a/flask/testsuite/basic.py +++ b/flask/testsuite/basic.py @@ -15,8 +15,7 @@ import flask import pickle import unittest from datetime import datetime -from threading import Thread -from time import sleep +from threading import Thread, Condition from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning from flask._compat import text_type from werkzeug.exceptions import BadRequest, NotFound @@ -1019,12 +1018,16 @@ class BasicFunctionalityTestCase(FlaskTestCase): def test_before_first_request_functions_concurrent(self): got = [] app = flask.Flask(__name__) + cv = Condition() @app.before_first_request def foo(): - sleep(1) + with cv: + cv.wait() got.append(42) c = app.test_client() def get_and_assert(): + with cv: + cv.notify() c.get("/") self.assert_equal(got, [42]) t = Thread(target=get_and_assert)