зеркало из https://github.com/github/vitess-gh.git
Merge pull request #627 from yaoshengzhe/fix_querylogz_race_condition
fix querylogz test race conditions
This commit is contained in:
Коммит
c3b687bd1f
|
@ -14,7 +14,6 @@ import (
|
|||
|
||||
log "github.com/golang/glog"
|
||||
"github.com/youtube/vitess/go/acl"
|
||||
"github.com/youtube/vitess/go/streamlog"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -73,20 +72,20 @@ var (
|
|||
|
||||
func init() {
|
||||
http.HandleFunc("/querylogz", func(w http.ResponseWriter, r *http.Request) {
|
||||
querylogzHandler(SqlQueryLogger, w, r)
|
||||
ch := SqlQueryLogger.Subscribe("querylogz")
|
||||
defer SqlQueryLogger.Unsubscribe(ch)
|
||||
querylogzHandler(ch, w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// querylogzHandler serves a human readable snapshot of the
|
||||
// current query log.
|
||||
func querylogzHandler(streamLogger *streamlog.StreamLogger, w http.ResponseWriter, r *http.Request) {
|
||||
func querylogzHandler(ch chan interface{}, w http.ResponseWriter, r *http.Request) {
|
||||
if err := acl.CheckAccessHTTP(r, acl.DEBUGGING); err != nil {
|
||||
acl.SendError(w, err)
|
||||
return
|
||||
}
|
||||
timeout, limit := parseTimeoutLimitParams(r)
|
||||
ch := streamLogger.Subscribe("querylogz")
|
||||
defer streamLogger.Unsubscribe(ch)
|
||||
startHTMLTable(w)
|
||||
defer endHTMLTable(w)
|
||||
w.Write(querylogzHeader)
|
||||
|
|
|
@ -13,7 +13,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/youtube/vitess/go/streamlog"
|
||||
"github.com/youtube/vitess/go/vt/tabletserver/planbuilder"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
@ -21,9 +20,10 @@ import (
|
|||
func TestQuerylogzHandlerInvalidSqlQueryStats(t *testing.T) {
|
||||
req, _ := http.NewRequest("GET", "/querylogz?timeout=0&limit=10", nil)
|
||||
response := httptest.NewRecorder()
|
||||
testLogger := streamlog.New("TestLogger", 100)
|
||||
testLogger.Send("test msg")
|
||||
querylogzHandler(testLogger, response, req)
|
||||
ch := make(chan interface{}, 1)
|
||||
ch <- "test msg"
|
||||
querylogzHandler(ch, response, req)
|
||||
close(ch)
|
||||
if !strings.Contains(response.Body.String(), "error") {
|
||||
t.Fatalf("should show an error page for an non SqlQueryStats")
|
||||
}
|
||||
|
@ -45,8 +45,6 @@ func TestQuerylogzHandler(t *testing.T) {
|
|||
logStats.CacheInvalidations = 3
|
||||
logStats.TransactionID = 131
|
||||
|
||||
testLogger := streamlog.New("TestLogger", 100)
|
||||
|
||||
// fast query
|
||||
fastQueryPattern := []string{
|
||||
`<td>Execute</td>`,
|
||||
|
@ -70,9 +68,11 @@ func TestQuerylogzHandler(t *testing.T) {
|
|||
`<td></td>`,
|
||||
}
|
||||
logStats.EndTime = logStats.StartTime.Add(1 * time.Millisecond)
|
||||
testLogger.Send(logStats)
|
||||
response := httptest.NewRecorder()
|
||||
querylogzHandler(testLogger, response, req)
|
||||
ch := make(chan interface{}, 1)
|
||||
ch <- logStats
|
||||
querylogzHandler(ch, response, req)
|
||||
close(ch)
|
||||
body, _ := ioutil.ReadAll(response.Body)
|
||||
checkQuerylogzHasStats(t, fastQueryPattern, logStats, body)
|
||||
|
||||
|
@ -99,9 +99,11 @@ func TestQuerylogzHandler(t *testing.T) {
|
|||
`<td></td>`,
|
||||
}
|
||||
logStats.EndTime = logStats.StartTime.Add(20 * time.Millisecond)
|
||||
testLogger.Send(logStats)
|
||||
response = httptest.NewRecorder()
|
||||
querylogzHandler(testLogger, response, req)
|
||||
ch = make(chan interface{}, 1)
|
||||
ch <- logStats
|
||||
querylogzHandler(ch, response, req)
|
||||
close(ch)
|
||||
body, _ = ioutil.ReadAll(response.Body)
|
||||
checkQuerylogzHasStats(t, mediumQueryPattern, logStats, body)
|
||||
|
||||
|
@ -128,8 +130,10 @@ func TestQuerylogzHandler(t *testing.T) {
|
|||
`<td></td>`,
|
||||
}
|
||||
logStats.EndTime = logStats.StartTime.Add(500 * time.Millisecond)
|
||||
testLogger.Send(logStats)
|
||||
querylogzHandler(testLogger, response, req)
|
||||
ch = make(chan interface{}, 1)
|
||||
ch <- logStats
|
||||
querylogzHandler(ch, response, req)
|
||||
close(ch)
|
||||
body, _ = ioutil.ReadAll(response.Body)
|
||||
checkQuerylogzHasStats(t, slowQueryPattern, logStats, body)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче