Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for fetcher warning at server startup #1914

Merged
merged 3 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stored_requests/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ func newFetcher(cfg *config.StoredRequests, client *http.Client, db *sql.DB) (fe
if cfg.Postgres.FetcherQueries.QueryTemplate != "" {
glog.Infof("Loading Stored %s data via Postgres.\nQuery: %s", cfg.DataType(), cfg.Postgres.FetcherQueries.QueryTemplate)
idList = append(idList, db_fetcher.NewFetcher(db, cfg.Postgres.FetcherQueries.MakeQuery))
} else if cfg.Postgres.CacheInitialization.Query != "" && cfg.Postgres.PollUpdates.Query != "" {
//in this case data will be loaded to cache via poll for updates event
idList = append(idList, empty_fetcher.EmptyFetcher{})
}
if cfg.HTTP.Endpoint != "" {
glog.Infof("Loading Stored %s data via HTTP. endpoint=%s", cfg.DataType(), cfg.HTTP.Endpoint)
Expand Down
40 changes: 35 additions & 5 deletions stored_requests/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,42 @@ func isMemoryCacheType(cache stored_requests.CacheJSON) bool {
}

func TestNewEmptyFetcher(t *testing.T) {
fetcher := newFetcher(&config.StoredRequests{}, nil, nil)
if fetcher == nil {
t.Errorf("The fetcher should be non-nil, even with an empty config.")

type testCase struct {
config *config.StoredRequests
message string
}
testCases := []testCase{
{
config: &config.StoredRequests{},
message: "If the config is empty, and EmptyFetcher should be returned",
},
{
config: &config.StoredRequests{
Postgres: config.PostgresConfig{
CacheInitialization: config.PostgresCacheInitializer{
Query: "test query",
},
PollUpdates: config.PostgresUpdatePolling{
Query: "test poll query",
},
FetcherQueries: config.PostgresFetcherQueries{
QueryTemplate: "",
},
},
},
message: "If Postgres fetcher query is not defined, but Postgres Cache init query and Postgres update polling query are defined EmptyFetcher should be returned",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please also add test cases where PostgresFetcherQueries is supplied in the config but not PostgresUpdatePolling and PostgresCacheInitializer? And also one where all of them are supplied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, added!

},
}
if _, ok := fetcher.(empty_fetcher.EmptyFetcher); !ok {
t.Errorf("If the config is empty, and EmptyFetcher should be returned")

for _, test := range testCases {
fetcher := newFetcher(test.config, nil, nil)
if fetcher == nil {
t.Errorf("The fetcher should be non-nil.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using assert.NotNil here

}
if _, ok := fetcher.(empty_fetcher.EmptyFetcher); !ok {
t.Errorf(test.message)
}
}
}

Expand Down