Skip to content

Commit 53ac6dd

Browse files
authored
[es] Add mock http server for the tests (#7607)
## Which problem is this PR solving? - Resolves #7167 ## Description of the changes - Mocked the http calls using `httptest` package to return immediate response instead of waiting for requests to timeout. ## How was this change tested? - GOMAXPROCS=6 go test -count=1 -parallel 128 -p 16 ./internal/storage/v1/elasticsearch/ ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: Tushar Anand <[email protected]>
1 parent 2c8ca4b commit 53ac6dd

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

internal/storage/v1/elasticsearch/factory_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,15 @@ func TestESStorageFactoryWithConfig(t *testing.T) {
317317

318318
func TestESStorageFactoryWithConfigError(t *testing.T) {
319319
t.Parallel()
320+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
321+
if r.URL.Path == "/" {
322+
w.WriteHeader(http.StatusInternalServerError)
323+
return
324+
}
325+
}))
326+
defer server.Close()
320327
cfg := escfg.Configuration{
321-
Servers: []string{"http://invalid-host-name:65535"},
328+
Servers: []string{server.URL},
322329
DisableHealthCheck: true,
323330
LogLevel: "error",
324331
}

internal/storage/v1/elasticsearch/factoryv1_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ func TestArchiveFactory(t *testing.T) {
103103

104104
func TestFactoryInitializeErr(t *testing.T) {
105105
t.Parallel()
106+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
107+
if r.URL.Path == "/" {
108+
w.WriteHeader(http.StatusInternalServerError)
109+
}
110+
}))
111+
defer server.Close()
106112
tests := []struct {
107113
name string
108114
factory *Factory
@@ -116,7 +122,7 @@ func TestFactoryInitializeErr(t *testing.T) {
116122
{
117123
name: "server error",
118124
factory: &Factory{Options: &Options{Config: namespaceConfig{Configuration: escfg.Configuration{
119-
Servers: []string{"http://invalid-host-name:9200"},
125+
Servers: []string{server.URL},
120126
DisableHealthCheck: true,
121127
}}}},
122128
expectedErr: "failed to create Elasticsearch client",

0 commit comments

Comments
 (0)