From 79f68f7a2e8415abdcccae9fba975e575d55337e Mon Sep 17 00:00:00 2001 From: Nia Weiss Date: Fri, 25 Sep 2020 10:36:00 -0400 Subject: [PATCH] stop explicitly recalculating caches in tests This is no longer necessary, as caches now recalculate on read. Also, in general a user will not explicitly request recalculation, so it would make sense for our tests to reflect that. --- api.go | 3 ++- executor_test.go | 4 ---- holder.go | 2 ++ http/client_test.go | 5 ----- test/pilosa.go | 9 --------- 5 files changed, 4 insertions(+), 19 deletions(-) diff --git a/api.go b/api.go index 878744e12..b6e8187c5 100644 --- a/api.go +++ b/api.go @@ -780,7 +780,8 @@ func (api *API) Node() *Node { return &node } -// RecalculateCaches forces all TopN caches to be updated. Used mainly for integration tests. +// RecalculateCaches forces all TopN caches to be updated. +// This is done internally within a TopN query, but a user may want to do it ahead of time? func (api *API) RecalculateCaches(ctx context.Context) error { span, _ := tracing.StartSpanFromContext(ctx, "API.RecalculateCaches") defer span.Finish() diff --git a/executor_test.go b/executor_test.go index c44df08f1..a34041844 100644 --- a/executor_test.go +++ b/executor_test.go @@ -2943,10 +2943,6 @@ func TestExecutor_Execute_Remote_Row(t *testing.T) { `}); err != nil { t.Fatalf("querying remote: %v", err) } - err := c.GetNode(0).API.RecalculateCaches(context.Background()) - if err != nil { - t.Fatalf("recalculating caches: %v", err) - } if res, err := c.GetNode(1).API.Query(context.Background(), &pilosa.QueryRequest{ Index: "i", diff --git a/holder.go b/holder.go index 1874735f2..1b8700020 100644 --- a/holder.go +++ b/holder.go @@ -1154,6 +1154,8 @@ func (h *Holder) flushCaches() { // probably not practical to call in real-world workloads, but makes writing // integration tests much eaiser, since one doesn't have to wait 10 seconds // after setting bits to get expected response. +// This is mostly unnecessary now, as caches will automatically recalculate on read. +// However, a user may explicitly request calculation, in which case we should not defer it. func (h *Holder) recalculateCaches() { for _, index := range h.Indexes() { index.recalculateCaches() diff --git a/http/client_test.go b/http/client_test.go index 6943b9c1c..cfe51bde4 100644 --- a/http/client_test.go +++ b/http/client_test.go @@ -617,7 +617,6 @@ func TestClient_ImportKeys(t *testing.T) { }); err != nil { t.Fatal(err) } - cmd.MustRecalculateCaches(t) resp := cmd.QueryAPI(t, &pilosa.QueryRequest{ Index: "keyed", Query: "TopN(keyedf)", @@ -644,7 +643,6 @@ func TestClient_ImportKeys(t *testing.T) { }); err != nil { t.Fatal(err) } - cmd.MustRecalculateCaches(t) resp := cmd.QueryAPI(t, &pilosa.QueryRequest{ Index: "keyed", Query: "TopN(unkeyedf)", @@ -671,7 +669,6 @@ func TestClient_ImportKeys(t *testing.T) { }); err != nil { t.Fatal(err) } - cmd.MustRecalculateCaches(t) resp := cmd.QueryAPI(t, &pilosa.QueryRequest{ Index: "unkeyed", Query: "TopN(keyedf)", @@ -716,7 +713,6 @@ func TestClient_ImportKeys(t *testing.T) { }); err != nil { t.Fatal(err) } - cmd0.MustRecalculateCaches(t) resp := cmd0.QueryAPI(t, &pilosa.QueryRequest{ Index: "keyed", Query: "TopN(keyedf0)", @@ -748,7 +744,6 @@ func TestClient_ImportKeys(t *testing.T) { // Wait for translation replication. time.Sleep(500 * time.Millisecond) - cmd1.MustRecalculateCaches(t) resp := cmd1.QueryAPI(t, &pilosa.QueryRequest{ Index: "keyed", Query: "TopN(keyedf1)", diff --git a/test/pilosa.go b/test/pilosa.go index f34cf0381..be0aaa1fc 100644 --- a/test/pilosa.go +++ b/test/pilosa.go @@ -184,15 +184,6 @@ func (m *Command) QueryAPI(tb testing.TB, req *pilosa.QueryRequest) pilosa.Query return resp } -// MustRecalculateCaches calls RecalculateCaches on the command's API, and fails -// if there is an error. -func (m *Command) MustRecalculateCaches(tb testing.TB) { - err := m.API.RecalculateCaches(context.Background()) - if err != nil { - tb.Fatalf("recalcluating caches: %v", err) - } -} - // URL returns the base URL string for accessing the running program. func (m *Command) URL() string { return m.API.Node().URI.String() }