Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benraskin92 committed Oct 7, 2019
1 parent 84d86ad commit 9507918
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 26 deletions.
28 changes: 17 additions & 11 deletions src/query/api/v1/handler/database/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/m3db/m3/src/cluster/services"
dbconfig "github.com/m3db/m3/src/cmd/services/m3dbnode/config"
"github.com/m3db/m3/src/cmd/services/m3query/config"
"github.com/m3db/m3/src/query/api/v1/handler"
"github.com/m3db/m3/src/query/api/v1/handler/namespace"
"github.com/m3db/m3/src/x/instrument"
xtest "github.com/m3db/m3/src/x/test"
Expand All @@ -51,6 +52,11 @@ var (
testDBCfg = &dbconfig.DBConfiguration{
ListenAddress: "0.0.0.0:9000",
}
svcDefaultOptions = []handler.ServiceOptionsDefault{
func(o handler.ServiceOptions) handler.ServiceOptions {
return o
},
}
)

func SetupDatabaseTest(
Expand Down Expand Up @@ -92,7 +98,7 @@ func testLocalType(t *testing.T, providedType string, placementExists bool) {
mockClient, mockKV, mockPlacementService := SetupDatabaseTest(t, ctrl)
mockClient.EXPECT().Store(gomock.Any()).Return(mockKV, nil).AnyTimes()
createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down Expand Up @@ -206,7 +212,7 @@ func TestLocalTypeClusteredPlacementAlreadyExists(t *testing.T) {

mockClient, _, mockPlacementService := SetupDatabaseTest(t, ctrl)
createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down Expand Up @@ -253,7 +259,7 @@ func TestLocalTypeWithNumShards(t *testing.T) {
mockClient, mockKV, mockPlacementService := SetupDatabaseTest(t, ctrl)
mockClient.EXPECT().Store(gomock.Any()).Return(mockKV, nil).AnyTimes()
createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)

w := httptest.NewRecorder()
Expand Down Expand Up @@ -364,7 +370,7 @@ func TestLocalWithBlockSizeNanos(t *testing.T) {
mockClient, mockKV, mockPlacementService := SetupDatabaseTest(t, ctrl)
mockClient.EXPECT().Store(gomock.Any()).Return(mockKV, nil).AnyTimes()
createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down Expand Up @@ -475,7 +481,7 @@ func TestLocalWithBlockSizeExpectedSeriesDatapointsPerHour(t *testing.T) {
mockClient, mockKV, mockPlacementService := SetupDatabaseTest(t, ctrl)
mockClient.EXPECT().Store(gomock.Any()).Return(mockKV, nil).AnyTimes()
createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down Expand Up @@ -598,7 +604,7 @@ func TestClusterTypeHostsPlacementAlreadyExistsHostsProvided(t *testing.T) {
mockClient, _, mockPlacementService := SetupDatabaseTest(t, ctrl)
mockClient.EXPECT().Store(gomock.Any()).Return(nil, nil).AnyTimes()
createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down Expand Up @@ -654,7 +660,7 @@ func TestClusterTypeHostsPlacementAlreadyExistsExistingIsLocal(t *testing.T) {

mockClient, _, mockPlacementService := SetupDatabaseTest(t, ctrl)
createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down Expand Up @@ -701,7 +707,7 @@ func testClusterTypeHosts(t *testing.T, placementExists bool) {
mockClient, mockKV, mockPlacementService := SetupDatabaseTest(t, ctrl)
mockClient.EXPECT().Store(gomock.Any()).Return(mockKV, nil).AnyTimes()
createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down Expand Up @@ -849,7 +855,7 @@ func TestClusterTypeHostsWithIsolationGroup(t *testing.T) {
mockClient.EXPECT().Store(gomock.Any()).Return(mockKV, nil)

createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down Expand Up @@ -980,7 +986,7 @@ func TestClusterTypeMissingHostnames(t *testing.T) {
mockPlacementService.EXPECT().Placement().Return(nil, kv.ErrNotFound)

createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
testDBCfg, instrument.NewOptions())
testDBCfg, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down Expand Up @@ -1011,7 +1017,7 @@ func TestBadType(t *testing.T) {
mockPlacementService.EXPECT().Placement().Return(nil, kv.ErrNotFound)

createHandler, err := NewCreateHandler(mockClient, config.Configuration{},
nil, instrument.NewOptions())
nil, svcDefaultOptions, instrument.NewOptions())
require.NoError(t, err)
w := httptest.NewRecorder()

Expand Down
6 changes: 3 additions & 3 deletions src/query/api/v1/handler/namespace/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestNamespaceAddHandler(t *testing.T) {
req := httptest.NewRequest("POST", "/namespace", strings.NewReader(jsonInput))
require.NotNil(t, req)

addHandler.ServeHTTP(w, req)
addHandler.ServeHTTP(svcDefaults, w, req)

resp := w.Result()
body, err := ioutil.ReadAll(resp.Body)
Expand All @@ -100,7 +100,7 @@ func TestNamespaceAddHandler(t *testing.T) {

mockKV.EXPECT().Get(M3DBNodeNamespacesKey).Return(nil, kv.ErrNotFound)
mockKV.EXPECT().CheckAndSet(M3DBNodeNamespacesKey, gomock.Any(), gomock.Not(nil)).Return(1, nil)
addHandler.ServeHTTP(w, req)
addHandler.ServeHTTP(svcDefaults, w, req)

resp = w.Result()
body, _ = ioutil.ReadAll(resp.Body)
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestNamespaceAddHandler_Conflict(t *testing.T) {
mockKV.EXPECT().Get(M3DBNodeNamespacesKey).Return(mockValue, nil)

w := httptest.NewRecorder()
addHandler.ServeHTTP(w, req)
addHandler.ServeHTTP(svcDefaults, w, req)
resp := w.Result()
assert.Equal(t, http.StatusConflict, resp.StatusCode)
}
17 changes: 12 additions & 5 deletions src/query/api/v1/handler/namespace/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
nsproto "github.com/m3db/m3/src/dbnode/generated/proto/namespace"
"github.com/m3db/m3/src/dbnode/namespace"
"github.com/m3db/m3/src/dbnode/namespace/kvadmin"
apihandler "github.com/m3db/m3/src/query/api/v1/handler"
"github.com/m3db/m3/src/x/instrument"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -94,6 +95,12 @@ message ImportedMessage {
`
)

var (
svcDefaults = apihandler.ServiceNameAndDefaults{
ServiceName: "m3db",
}
)

func genTestJSON(t *testing.T) string {
tempDir, err := ioutil.TempDir("", "schema_deploy_test")
require.NoError(t, err)
Expand Down Expand Up @@ -144,7 +151,7 @@ func TestSchemaDeploy_KVKeyNotFound(t *testing.T) {
require.NotNil(t, req)

mockKV.EXPECT().Get(M3DBNodeNamespacesKey).Return(nil, kv.ErrNotFound)
addHandler.ServeHTTP(w, req)
addHandler.ServeHTTP(svcDefaults, w, req)

resp := w.Result()
body, err := ioutil.ReadAll(resp.Body)
Expand Down Expand Up @@ -186,7 +193,7 @@ func TestSchemaDeploy(t *testing.T) {
req := httptest.NewRequest("POST", "/schema", strings.NewReader(testSchemaJSON))
require.NotNil(t, req)

schemaHandler.ServeHTTP(w, req)
schemaHandler.ServeHTTP(svcDefaults, w, req)

resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
Expand Down Expand Up @@ -239,7 +246,7 @@ func TestSchemaDeploy_NamespaceNotFound(t *testing.T) {
mockKV.EXPECT().Get(M3DBNodeNamespacesKey).Return(mockValue, nil)

w := httptest.NewRecorder()
schemaHandler.ServeHTTP(w, req)
schemaHandler.ServeHTTP(svcDefaults, w, req)
resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
Expand Down Expand Up @@ -270,7 +277,7 @@ func TestSchemaReset(t *testing.T) {
req := httptest.NewRequest("DELETE", "/schema", strings.NewReader(jsonInput))
require.NotNil(t, req)

schemaHandler.ServeHTTP(w, req)
schemaHandler.ServeHTTP(svcDefaults, w, req)

resp := w.Result()
body, _ := ioutil.ReadAll(resp.Body)
Expand All @@ -281,7 +288,7 @@ func TestSchemaReset(t *testing.T) {
require.NotNil(t, req)
req.Header.Add("Force", "true")

schemaHandler.ServeHTTP(w, req)
schemaHandler.ServeHTTP(svcDefaults, w, req)

resp = w.Result()
body, _ = ioutil.ReadAll(resp.Body)
Expand Down
44 changes: 37 additions & 7 deletions src/query/api/v1/httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ var (
defaultLookbackDuration = time.Minute
defaultCPUProfileduration = 5 * time.Second
defaultPlacementServices = []string{"m3db"}
svcDefaultOptions = []handler.ServiceOptionsDefault{
func(o handler.ServiceOptions) handler.ServiceOptions {
return o
},
}
)

func makeTagOptions() models.TagOptions {
Expand Down Expand Up @@ -95,7 +100,8 @@ func setupHandler(store storage.Storage) (*Handler, error) {
models.QueryContextOptions{},
instrumentOpts,
defaultCPUProfileduration,
defaultPlacementServices)
defaultPlacementServices,
svcDefaultOptions)
}

func TestHandlerFetchTimeoutError(t *testing.T) {
Expand All @@ -107,9 +113,21 @@ func TestHandlerFetchTimeoutError(t *testing.T) {
dbconfig := &dbconfig.DBConfiguration{Client: client.Configuration{FetchTimeout: &negValue}}
engine := newEngine(storage, time.Minute, nil, instrument.NewOptions())
cfg := config.Configuration{LookbackDuration: &defaultLookbackDuration}
_, err := NewHandler(downsamplerAndWriter, makeTagOptions(), engine, nil, nil,
cfg, dbconfig, nil, handler.NewFetchOptionsBuilder(handler.FetchOptionsBuilderOptions{}),
models.QueryContextOptions{}, instrument.NewOptions(), defaultCPUProfileduration, defaultPlacementServices)
_, err := NewHandler(
downsamplerAndWriter,
makeTagOptions(),
engine,
nil,
nil,
cfg,
dbconfig,
nil,
handler.NewFetchOptionsBuilder(handler.FetchOptionsBuilderOptions{}),
models.QueryContextOptions{},
instrument.NewOptions(),
defaultCPUProfileduration,
defaultPlacementServices,
svcDefaultOptions)

require.Error(t, err)
}
Expand All @@ -123,9 +141,21 @@ func TestHandlerFetchTimeout(t *testing.T) {
dbconfig := &dbconfig.DBConfiguration{Client: client.Configuration{FetchTimeout: &fourMin}}
engine := newEngine(storage, time.Minute, nil, instrument.NewOptions())
cfg := config.Configuration{LookbackDuration: &defaultLookbackDuration}
h, err := NewHandler(downsamplerAndWriter, makeTagOptions(), engine,
nil, nil, cfg, dbconfig, nil, handler.NewFetchOptionsBuilder(handler.FetchOptionsBuilderOptions{}),
models.QueryContextOptions{}, instrument.NewOptions(), defaultCPUProfileduration, defaultPlacementServices)
h, err := NewHandler(
downsamplerAndWriter,
makeTagOptions(),
engine,
nil,
nil,
cfg,
dbconfig,
nil,
handler.NewFetchOptionsBuilder(handler.FetchOptionsBuilderOptions{}),
models.QueryContextOptions{},
instrument.NewOptions(),
defaultCPUProfileduration,
defaultPlacementServices,
svcDefaultOptions)
require.NoError(t, err)
assert.Equal(t, 4*time.Minute, h.timeoutOpts.FetchTimeout)
}
Expand Down

0 comments on commit 9507918

Please sign in to comment.