Skip to content

Commit

Permalink
Enabling HTTP retries for FCM and IID (#217)
Browse files Browse the repository at this point in the history
* Enabling HTTP retries for FCM and IID

* Disabling retries for tests
  • Loading branch information
hiranya911 committed Jan 23, 2019
1 parent 6ea9a02 commit 761eb88
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- [added] Implemented HTTP retries for the `db` package. This package
now retries HTTP calls on low-level connection and socket read errors, as
well as HTTP 500 and 503 errors.
- [fixed] Updated `messaging.Client` and `iid.Client` to use the new
HTTP client API with retries support.

# v3.6.0

Expand Down
5 changes: 2 additions & 3 deletions iid/iid.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net/http"

"firebase.google.com/go/internal"
"google.golang.org/api/transport"
)

const iidEndpoint = "https://console.firebase.google.com/v1"
Expand Down Expand Up @@ -117,14 +116,14 @@ func NewClient(ctx context.Context, c *internal.InstanceIDConfig) (*Client, erro
return nil, errors.New("project id is required to access instance id client")
}

hc, _, err := transport.NewHTTPClient(ctx, c.Opts...)
hc, _, err := internal.NewHTTPClient(ctx, c.Opts...)
if err != nil {
return nil, err
}

return &Client{
endpoint: iidEndpoint,
client: &internal.HTTPClient{Client: hc},
client: hc,
project: c.ProjectID,
}, nil
}
Expand Down
1 change: 1 addition & 0 deletions iid/iid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestDeleteInstanceIDError(t *testing.T) {
t.Fatal(err)
}
client.endpoint = ts.URL
client.client.RetryConfig = nil

errorHandlers := map[int]func(error) bool{
http.StatusBadRequest: IsInvalidArgument,
Expand Down
5 changes: 2 additions & 3 deletions messaging/messaging.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"time"

"firebase.google.com/go/internal"
"google.golang.org/api/transport"
)

const (
Expand Down Expand Up @@ -653,15 +652,15 @@ func NewClient(ctx context.Context, c *internal.MessagingConfig) (*Client, error
return nil, errors.New("project ID is required to access Firebase Cloud Messaging client")
}

hc, _, err := transport.NewHTTPClient(ctx, c.Opts...)
hc, _, err := internal.NewHTTPClient(ctx, c.Opts...)
if err != nil {
return nil, err
}

return &Client{
fcmEndpoint: messagingEndpoint,
iidEndpoint: iidEndpoint,
client: &internal.HTTPClient{Client: hc},
client: hc,
project: c.ProjectID,
version: "Go/Admin/" + c.Version,
}, nil
Expand Down
2 changes: 2 additions & 0 deletions messaging/messaging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ func TestSendError(t *testing.T) {
t.Fatal(err)
}
client.fcmEndpoint = ts.URL
client.client.RetryConfig = nil

cases := []struct {
resp, want string
Expand Down Expand Up @@ -1150,6 +1151,7 @@ func TestTopicManagementError(t *testing.T) {
t.Fatal(err)
}
client.iidEndpoint = ts.URL
client.client.RetryConfig = nil

cases := []struct {
resp, want string
Expand Down

0 comments on commit 761eb88

Please sign in to comment.