From b020f60390d033f555cc7d22a2fd173d836d5e38 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 7 Dec 2013 10:53:30 -0800 Subject: [PATCH] search: add test for earlier fix in commit 1e1183a8bf0 Change-Id: I95c0f885079de17cd1c52b9ad40861c96eb5308c --- pkg/search/export_test.go | 2 ++ pkg/search/query_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/pkg/search/export_test.go b/pkg/search/export_test.go index 9d26b8546..a24f340f2 100644 --- a/pkg/search/export_test.go +++ b/pkg/search/export_test.go @@ -22,6 +22,8 @@ func SetTestHookBug121(hook func()) { func ExportCandSource() string { return candSource } +func ExportBufferedConst() int { return buffered } + func (s *SearchQuery) ExportPlannedQuery() *SearchQuery { return s.plannedQuery() } diff --git a/pkg/search/query_test.go b/pkg/search/query_test.go index 65ba6d9e9..d5a98fdad 100644 --- a/pkg/search/query_test.go +++ b/pkg/search/query_test.go @@ -566,6 +566,42 @@ func TestQueryRecentPermanodes(t *testing.T) { }) } +func TestLimitDoesntDeadlock(t *testing.T) { + // TODO: care about classic (allIndexTypes) too? + testQueryTypes(t, memIndexTypes, func(qt *queryTest) { + id := qt.id + + const limit = 2 + for i := 0; i < ExportBufferedConst()+limit+1; i++ { + pn := id.NewPlannedPermanode(fmt.Sprint(i)) + id.SetAttribute(pn, "foo", "bar") + } + + req := &SearchQuery{ + Constraint: &Constraint{ + Permanode: &PermanodeConstraint{}, + }, + Limit: limit, + Sort: UnspecifiedSort, + Describe: &DescribeRequest{}, + } + h := qt.Handler() + gotRes := make(chan bool, 1) + go func() { + _, err := h.Query(req) + if err != nil { + qt.t.Error(err) + } + gotRes <- true + }() + select { + case <-gotRes: + case <-time.After(5 * time.Second): + t.Error("timeout; deadlock?") + } + }) +} + func prettyJSON(v interface{}) string { b, err := json.MarshalIndent(v, "", " ") if err != nil {