Reduce 503 retries for tests

This commit is contained in:
Abhishek Pandey 2024-02-09 17:55:33 -08:00
parent f43647076e
commit 32569752d8
2 changed files with 14 additions and 8 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/internal/tester/tconfig"
"github.com/alcionai/corso/src/pkg/count"
"github.com/alcionai/corso/src/pkg/services/m365/api/graph"
)
// ---------------------------------------------------------------------------
@ -107,13 +108,10 @@ func (suite *EventsPagerUnitSuite) TestEventsList() {
Reply(http.StatusOK).
JSON(validEventsListSingleNextLinkResponse)
// Number of retries and delay between retries is handled by a kiota
// middleware. We can change the default config parameters when setting
// up the mock in a later PR.
gock.New(graphAPIHostURL).
Get(nextLinkPath).
AddMatcher(pageSizeMatcher(t, expectedPageSize)).
Times(4).
Times(2). // retry count is configured to 1
Reply(http.StatusServiceUnavailable).
BodyString("").
Type("text/plain")
@ -241,7 +239,9 @@ func (suite *EventsPagerUnitSuite) TestEventsList() {
creds, err := a.M365Config()
require.NoError(t, err, clues.ToCore(err))
client, err := gockClient(creds, count.New())
// Run with a single retry since 503 retries are exponential and
// the test will take a long time to run.
client, err := gockClient(creds, count.New(), graph.MaxRetries(1))
require.NoError(t, err, clues.ToCore(err))
t.Cleanup(gock.Off)

View File

@ -23,13 +23,19 @@ import (
// GockClient produces a new exchange api client that can be
// mocked using gock.
func gockClient(creds account.M365Config, counter *count.Bus) (Client, error) {
s, err := graph.NewGockService(creds, counter)
func gockClient(
creds account.M365Config,
counter *count.Bus,
opts ...graph.Option,
) (Client, error) {
s, err := graph.NewGockService(creds, counter, opts...)
if err != nil {
return Client{}, err
}
li, err := graph.NewGockService(creds, counter, graph.NoTimeout())
opts = append(opts, graph.NoTimeout())
li, err := graph.NewGockService(creds, counter, opts...)
if err != nil {
return Client{}, err
}