From dc7984d63d17465b60fcaaeb36c9a45a03acf491 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 22 May 2023 15:25:22 -0500 Subject: [PATCH 1/2] Delete indexed documents instead of the index itself --- testsuite/testsuite.go | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/testsuite/testsuite.go b/testsuite/testsuite.go index 8ab29dc2f..5a6c2294a 100644 --- a/testsuite/testsuite.go +++ b/testsuite/testsuite.go @@ -88,13 +88,17 @@ func Runtime() (context.Context, *runtime.Runtime) { return context.Background(), rt } -func ReindexElastic() { +// ReindexElastic updates elastic indexing +func ReindexElastic() int { db := getDB() contactsIndexer := indexers.NewContactIndexer(elasticURL, elasticContactsIndex, 1, 1, 100) contactsIndexer.Index(db.DB, false, false) + indexed := contactsIndexer.Stats().Indexed - time.Sleep(1 * time.Second) + time.Sleep(1000 * time.Millisecond) + + return int(indexed) } // returns an open test database pool @@ -195,27 +199,26 @@ func resetStorage() { must(os.RemoveAll(SessionStorageDir)) } -// delete -func resetElastic(ctx context.Context) { +// reset indexed data in elastic +func resetElastic(ctx context.Context) (int, int) { es, err := elastic.NewSimpleClient(elastic.SetURL(elasticURL), elastic.SetSniff(false)) noError(err) exists, err := es.IndexExists(elasticContactsIndex).Do(ctx) noError(err) + numDeleted := 0 + if exists { - // get any indexes for the contacts alias - ar, err := es.Aliases().Index(elasticContactsIndex).Do(ctx) + resp, err := es.DeleteByQuery(elasticContactsIndex).Refresh("true").Routing("1", "2").Query(elastic.NewMatchAllQuery().Boost(1.0)).Do(ctx) noError(err) - // and delete them - for _, index := range ar.IndicesByAlias(elasticContactsIndex) { - _, err := es.DeleteIndex(index).Do(ctx) - noError(err) - } + numDeleted = int(resp.Deleted) } - ReindexElastic() + time.Sleep(1000 * time.Millisecond) + + return numDeleted, ReindexElastic() } var sqlResetTestData = ` From 05454b54eee0261968780e5059b8be8526e9d6b8 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Tue, 23 May 2023 16:10:54 -0500 Subject: [PATCH 2/2] Refresh index before deleting --- testsuite/testsuite.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testsuite/testsuite.go b/testsuite/testsuite.go index 761ed089f..99dcacc3e 100644 --- a/testsuite/testsuite.go +++ b/testsuite/testsuite.go @@ -216,6 +216,9 @@ func resetElastic(ctx context.Context) (int, int) { numDeleted := 0 if exists { + _, err = es.Refresh(elasticContactsIndex).Do(ctx) + noError(err) + resp, err := es.DeleteByQuery(elasticContactsIndex).Refresh("true").Routing("1", "2").Query(elastic.NewMatchAllQuery()).Do(ctx) noError(err)