Skip to content

Commit

Permalink
http client upfront
Browse files Browse the repository at this point in the history
Signed-off-by: Manik2708 <[email protected]>
  • Loading branch information
Manik2708 committed Dec 12, 2024
1 parent 3a58976 commit c61ef9c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions plugin/storage/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -71,8 +72,7 @@ func (s *ESStorageIntegration) getVersion() (uint, error) {
return uint(esVersion), nil
}

func (s *ESStorageIntegration) initializeES(t *testing.T, allTagsAsFields bool) {
c := getESHttpClient(t)
func (s *ESStorageIntegration) initializeES(t *testing.T, c *http.Client, allTagsAsFields bool) {
rawClient, err := elastic.NewClient(
elastic.SetURL(queryURL),
elastic.SetSniff(false),
Expand Down Expand Up @@ -149,8 +149,7 @@ func (s *ESStorageIntegration) initSpanstore(t *testing.T, allTagsAsFields bool)
require.NoError(t, err)
}

func healthCheck(t *testing.T) error {
c := getESHttpClient(t)
func healthCheck(c *http.Client) error {
for i := 0; i < 200; i++ {
if resp, err := c.Get(queryURL); err == nil {
return resp.Body.Close()
Expand All @@ -162,10 +161,8 @@ func healthCheck(t *testing.T) error {

func testElasticsearchStorage(t *testing.T, allTagsAsFields bool) {
SkipUnlessEnv(t, "elasticsearch", "opensearch")
t.Cleanup(func() {
testutils.VerifyGoLeaksOnce(t)
})
require.NoError(t, healthCheck(t))
c := getESHttpClient(t)
require.NoError(t, healthCheck(c))
s := &ESStorageIntegration{
StorageIntegration: StorageIntegration{
Fixtures: LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
Expand All @@ -175,11 +172,14 @@ func testElasticsearchStorage(t *testing.T, allTagsAsFields bool) {
GetOperationsMissingSpanKind: true,
},
}
s.initializeES(t, allTagsAsFields)
s.initializeES(t, c, allTagsAsFields)
s.RunAll(t)
}

func TestElasticsearchStorage(t *testing.T) {
t.Cleanup(func() {
testutils.VerifyGoLeaksOnce(t)
})
testElasticsearchStorage(t, false)
}

Expand All @@ -189,9 +189,10 @@ func TestElasticsearchStorage_AllTagsAsObjectFields(t *testing.T) {

func TestElasticsearchStorage_IndexTemplates(t *testing.T) {
SkipUnlessEnv(t, "elasticsearch", "opensearch")
require.NoError(t, healthCheck(t))
c := getESHttpClient(t)
require.NoError(t, healthCheck(c))
s := &ESStorageIntegration{}
s.initializeES(t, true)
s.initializeES(t, c, true)
esVersion, err := s.getVersion()
require.NoError(t, err)
// TODO abstract this into pkg/es/client.IndexManagementLifecycleAPI
Expand Down

0 comments on commit c61ef9c

Please sign in to comment.