Skip to content

Commit

Permalink
Merge branch '0.10-maintenance'
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Feb 9, 2014
2 parents c938771 + 141a553 commit a950358
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Version 0.10.2
- Fixed an etags bug when sending a file streams with a name.
- Fixed `send_from_directory` not expanding to the application root path
correctly.
- Changed logic of before first request handlers to flip the flag after
invoking. This will allow some uses that are potentially dangerous but
should probably be permitted.

Version 0.10.1
--------------
Expand Down
2 changes: 1 addition & 1 deletion flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,9 +1491,9 @@ def try_trigger_before_first_request_functions(self):
with self._before_request_lock:
if self._got_first_request:
return
self._got_first_request = True
for func in self.before_first_request_funcs:
func()
self._got_first_request = True

def make_default_options_response(self):
"""This method is called to create the default `OPTIONS` response.
Expand Down
23 changes: 22 additions & 1 deletion flask/testsuite/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import pickle
import unittest
from datetime import datetime
from threading import Thread
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
Expand Down Expand Up @@ -1095,6 +1095,27 @@ def foo():
self.assert_equal(got, [42])
self.assert_true(app.got_first_request)

def test_before_first_request_functions_concurrent(self):
got = []
app = flask.Flask(__name__)
cv = Condition()
@app.before_first_request
def foo():
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)
t.start()
get_and_assert()
t.join()
self.assert_true(app.got_first_request)

def test_routing_redirect_debugging(self):
app = flask.Flask(__name__)
app.debug = True
Expand Down

0 comments on commit a950358

Please sign in to comment.