Skip to content

Commit

Permalink
fix test race
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Oct 10, 2015
1 parent c33ce09 commit 709edad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions macaron.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ type Macaron struct {
handlers []Handler
action Handler

urlPrefix string // For suburl support.
hasURLPrefix bool
urlPrefix string // For suburl support.
*Router

logger *log.Logger
Expand Down Expand Up @@ -163,7 +164,9 @@ func (m *Macaron) createContext(rw http.ResponseWriter, req *http.Request) *Cont
// Useful if you want to control your own HTTP server.
// Be aware that none of middleware will run without registering any router.
func (m *Macaron) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
req.URL.Path = strings.TrimPrefix(req.URL.Path, m.urlPrefix)
if m.hasURLPrefix {
req.URL.Path = strings.TrimPrefix(req.URL.Path, m.urlPrefix)
}
for _, h := range m.befores {
if h(rw, req) {
return
Expand Down Expand Up @@ -212,6 +215,7 @@ func (m *Macaron) Run(args ...interface{}) {
// SetURLPrefix sets URL prefix of router layer, so that it support suburl.
func (m *Macaron) SetURLPrefix(prefix string) {
m.urlPrefix = prefix
m.hasURLPrefix = len(m.urlPrefix) > 0
}

// ____ ____ .__ ___. .__
Expand Down
2 changes: 1 addition & 1 deletion macaron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ func Test_Macaron_Basic_NoRace(t *testing.T) {
// Ensure append will not realloc to trigger the race condition
m.handlers = handlers[:1]
m.Get("/", func() {})
req, _ := http.NewRequest("GET", "/", nil)
for i := 0; i < 2; i++ {
go func() {
req, _ := http.NewRequest("GET", "/", nil)
resp := httptest.NewRecorder()
m.ServeHTTP(resp, req)
}()
Expand Down

0 comments on commit 709edad

Please sign in to comment.