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 retry mechanism for APNS #54

Merged
merged 66 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
f1ea19a
Fix data races wip
miguelreiswildlife Apr 8, 2024
abee50a
wip
miguelreiswildlife Apr 9, 2024
54c88be
wip
miguelreiswildlife Apr 9, 2024
c208102
wip
miguelreiswildlife Apr 9, 2024
0fe1cf9
wip
miguelreiswildlife Apr 9, 2024
c643c4e
wip
miguelreiswildlife Apr 9, 2024
208763f
wip
miguelreiswildlife Apr 9, 2024
40b6be8
Fix timeout
miguelreiswildlife Apr 9, 2024
7e632d1
fix test
miguelreiswildlife Apr 9, 2024
b47b27e
Add missing lock
miguelreiswildlife Apr 9, 2024
c407513
Rollback to lower case
miguelreiswildlife Apr 10, 2024
1cb6161
Remove commented code
miguelreiswildlife Apr 10, 2024
9493f8f
Add missing lock/unlock
miguelreiswildlife Apr 10, 2024
75ce4ec
Use single lock/unlock on invalid_token_handler
miguelreiswildlife Apr 10, 2024
c9c08f5
Add missing lock/unlock
miguelreiswildlife Apr 10, 2024
19af568
Prevent deadlock on retry
miguelreiswildlife Apr 11, 2024
6e9f015
More logs on apns initialization
miguelreiswildlife Apr 11, 2024
518cf23
More logs on apns client
miguelreiswildlife Apr 11, 2024
ed9430e
Try fix infinite loop
miguelreiswildlife Apr 11, 2024
ccd487a
Fix mock
miguelreiswildlife Apr 11, 2024
48e9947
More logging
miguelreiswildlife Apr 12, 2024
6187d5c
More logs
miguelreiswildlife Apr 12, 2024
49480fa
Call Resume only when Pause is called
miguelreiswildlife Apr 15, 2024
4e75896
Remove pause + resume
miguelreiswildlife Apr 16, 2024
7f40896
Fix data races
miguelreiswildlife Apr 16, 2024
0613681
Some more data race fixes
miguelreiswildlife Apr 18, 2024
2e30896
Add e2e tests for apns
miguelreiswildlife Apr 23, 2024
f9caa82
Fix test
miguelreiswildlife Apr 23, 2024
8e312ed
Try fix test on CI
miguelreiswildlife Apr 30, 2024
27bd099
Try fix tests
miguelreiswildlife Apr 30, 2024
253b940
Fix test
miguelreiswildlife Apr 30, 2024
54f7688
Fix tests
miguelreiswildlife Apr 30, 2024
9a39608
Fix tests
miguelreiswildlife Apr 30, 2024
6d02dd7
Fix tests
miguelreiswildlife Apr 30, 2024
a3084df
Fix tests
miguelreiswildlife Apr 30, 2024
b3a459a
Fix tests
miguelreiswildlife May 2, 2024
313b638
Fix tests
miguelreiswildlife May 2, 2024
5a2e5bf
Remove unnecessary config file
miguelreiswildlife May 2, 2024
c10c836
Increase request timeout
miguelreiswildlife May 2, 2024
d5e3ddc
Add a log + remove code
miguelreiswildlife May 3, 2024
c8a53b3
Fix test name
miguelreiswildlife May 3, 2024
3d053a0
Allow go stats report on e2e
miguelreiswildlife May 3, 2024
1bd8d6d
Fix error log
miguelreiswildlife May 7, 2024
9f3341b
Replace images on CI
miguelreiswildlife May 8, 2024
1fe3df4
Try fix CI
miguelreiswildlife May 9, 2024
0174947
Try fix CI
miguelreiswildlife May 9, 2024
3270a11
Fix test
miguelreiswildlife May 9, 2024
1e7944b
Fix test
miguelreiswildlife May 9, 2024
f620687
GinkgoRecover
miguelreiswildlife May 9, 2024
41fe883
Try fix kafka on CI
miguelreiswildlife May 9, 2024
61fb262
Fix test
miguelreiswildlife May 9, 2024
05f5121
Try fix Ci on Kafka
miguelreiswildlife May 9, 2024
b28b9d3
Fix action yaml
miguelreiswildlife May 9, 2024
dc45532
Try fix Kafka address on CI
miguelreiswildlife May 9, 2024
18ad666
Use localhost on CI
miguelreiswildlife May 9, 2024
9efd2bc
Try fix CI
miguelreiswildlife May 9, 2024
814359e
Add health check on kafka container on CI
miguelreiswildlife May 9, 2024
fad9f74
Increase health check timeout
miguelreiswildlife May 9, 2024
e8f200f
Change kafka replication factor on Ci
miguelreiswildlife May 9, 2024
57d4335
Change hostname on kafka health check on CI
miguelreiswildlife May 9, 2024
3e8de0b
Change eventually assertion
miguelreiswildlife May 9, 2024
16c7672
Try fix test
miguelreiswildlife May 9, 2024
469d776
Try fix test
miguelreiswildlife May 9, 2024
068da77
Tweak configs
miguelreiswildlife May 9, 2024
0f273f8
Try fix tests
miguelreiswildlife May 9, 2024
c5deb05
Try fix test
miguelreiswildlife May 9, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Build
run: docker run -v $PWD:/go/src/github.com/topfreegames/pusher tfgco/pusher:ci-test go build -v -o bin/pusher main.go
- name: Test
run: docker run -v $PWD:/go/src/github.com/topfreegames/pusher tfgco/pusher:ci-test ginkgo -v -r --randomizeAllSpecs --randomizeSuites --cover --focus="\[Unit\].*" .
run: docker run -v $PWD:/go/src/github.com/topfreegames/pusher tfgco/pusher:ci-test ginkgo -v -r --randomizeAllSpecs --randomizeSuites --cover --focus="\[Unit\].*" --skipPackage=e2e .
- name: Lint
continue-on-error: true
run: docker run -v $PWD:/go/src/github.com/topfreegames/pusher tfgco/pusher:ci-test golangci-lint run
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ test-unit:
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo
@export $ACK_GINKGO_RC=true
@$(GINKGO) --race -trace -r --randomizeAllSpecs --randomizeSuites --cover --focus="\[Unit\].*" .
@$(MAKE) test-coverage-func
@$(GINKGO) -trace -r --randomizeAllSpecs --randomizeSuites --cover --focus="\[Unit\].*" --skipPackage=e2e .
@#$(MAKE) test-coverage-func
@echo
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo "= Unit tests finished. ="
Expand All @@ -120,7 +120,7 @@ run-integration-test:
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo
@export $ACK_GINKGO_RC=true
@$(GINKGO) --race -trace -r -tags=integration --randomizeAllSpecs --randomizeSuites --focus="\[Integration\].*" .
@$(GINKGO) -trace -r -tags=integration --randomizeAllSpecs --randomizeSuites --focus="\[Integration\].*" .
@echo
@echo "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
@echo "= Integration tests finished. ="
Expand Down Expand Up @@ -173,4 +173,7 @@ integration-test-container-dev: build-image-dev start-deps-container-dev test-db

.PHONY: mocks
mocks:
$(MOCKGENERATE) -source=interfaces/client.go -destination=mocks/firebase/client.go
$(MOCKGENERATE) -source=interfaces/client.go -destination=mocks/firebase/client.go
$(MOCKGENERATE) -source=interfaces/apns.go -destination=mocks/interfaces/apns.go
$(MOCKGENERATE) -source=interfaces/statsd.go -destination=mocks/interfaces/statsd.go
$(MOCKGENERATE) -source=interfaces/feedback_reporter.go -destination=mocks/interfaces/feedback_reporter.go
12 changes: 7 additions & 5 deletions cmd/apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/topfreegames/pusher/config"
"github.com/topfreegames/pusher/interfaces"
"github.com/topfreegames/pusher/pusher"
"github.com/topfreegames/pusher/util"
)

func startApns(
debug, json, production bool,
config *viper.Viper,
vConfig *viper.Viper,
config *config.Config,
statsdClientOrNil interfaces.StatsDClient,
dbOrNil interfaces.DB,
queueOrNil interfaces.APNSPushQueue,
Expand All @@ -49,7 +51,7 @@ func startApns(
} else {
log.Level = logrus.InfoLevel
}
return pusher.NewAPNSPusher(production, config, log, statsdClientOrNil, dbOrNil, queueOrNil)
return pusher.NewAPNSPusher(production, vConfig, config, log, statsdClientOrNil, dbOrNil, queueOrNil)
}

// apnsCmd represents the apns command
Expand All @@ -58,19 +60,19 @@ var apnsCmd = &cobra.Command{
Short: "starts pusher in apns mode",
Long: `starts pusher in apns mode`,
Run: func(cmd *cobra.Command, args []string) {
config, err := util.NewViperWithConfigFile(cfgFile)
config, vConfig, err := config.NewConfigAndViper(cfgFile)
if err != nil {
panic(err)
}

sentryURL := config.GetString("sentry.url")
sentryURL := vConfig.GetString("sentry.url")
if sentryURL != "" {
raven.SetDSN(sentryURL)
}

ctx := context.Background()

apnsPusher, err := startApns(debug, json, production, config, nil, nil, nil)
apnsPusher, err := startApns(debug, json, production, vConfig, config, nil, nil, nil)
if err != nil {
raven.CaptureErrorAndWait(err, map[string]string{
"version": util.Version,
Expand Down
21 changes: 11 additions & 10 deletions cmd/apns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@ package cmd

import (
"fmt"
"github.com/topfreegames/pusher/config"
"os"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/topfreegames/pusher/mocks"
"github.com/topfreegames/pusher/util"
)

var _ = Describe("APNS", func() {
cfg := os.Getenv("CONFIG_FILE")
if cfg == "" {
cfg = "../config/test.yaml"
configFile := os.Getenv("CONFIG_FILE")
if configFile == "" {
configFile = "../config/test.yaml"
}

var config *viper.Viper
var vConfig *viper.Viper
var cfg *config.Config
var mockPushQueue *mocks.APNSPushQueueMock
var mockDB *mocks.PGMock
var mockStatsDClient *mocks.StatsDClientMock

BeforeEach(func() {
var err error
config, err = util.NewViperWithConfigFile(cfg)
cfg, vConfig, err = config.NewConfigAndViper(configFile)
Expect(err).NotTo(HaveOccurred())
mockDB = mocks.NewPGMock(0, 1)
mockPushQueue = mocks.NewAPNSPushQueueMock()
Expand All @@ -56,7 +57,7 @@ var _ = Describe("APNS", func() {

Describe("[Unit]", func() {
It("Should return apnsPusher without errors", func() {
apnsPusher, err := startApns(false, false, false, config, mockStatsDClient, mockDB, mockPushQueue)
apnsPusher, err := startApns(false, false, false, vConfig, cfg, mockStatsDClient, mockDB, mockPushQueue)
Expect(err).NotTo(HaveOccurred())
Expect(apnsPusher).NotTo(BeNil())
Expect(apnsPusher.ViperConfig).NotTo(BeNil())
Expand All @@ -66,21 +67,21 @@ var _ = Describe("APNS", func() {
})

It("Should set log to json format", func() {
apnsPusher, err := startApns(false, true, false, config, mockStatsDClient, mockDB, mockPushQueue)
apnsPusher, err := startApns(false, true, false, vConfig, cfg, mockStatsDClient, mockDB, mockPushQueue)
Expect(err).NotTo(HaveOccurred())
Expect(apnsPusher).NotTo(BeNil())
Expect(fmt.Sprintf("%T", apnsPusher.Logger.Formatter)).To(Equal(fmt.Sprintf("%T", &logrus.JSONFormatter{})))
})

It("Should set log to debug", func() {
apnsPusher, err := startApns(true, false, false, config, mockStatsDClient, mockDB, mockPushQueue)
apnsPusher, err := startApns(true, false, false, vConfig, cfg, mockStatsDClient, mockDB, mockPushQueue)
Expect(err).NotTo(HaveOccurred())
Expect(apnsPusher).NotTo(BeNil())
Expect(apnsPusher.Logger.Level).To(Equal(logrus.DebugLevel))
})

It("Should set log to production", func() {
apnsPusher, err := startApns(false, false, true, config, mockStatsDClient, mockDB, mockPushQueue)
apnsPusher, err := startApns(false, false, true, vConfig, cfg, mockStatsDClient, mockDB, mockPushQueue)
Expect(err).NotTo(HaveOccurred())
Expect(apnsPusher).NotTo(BeNil())
Expect(apnsPusher.IsProduction).To(BeTrue())
Expand Down
30 changes: 29 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,34 @@ type (
// Config is the struct that holds all the configuration for the Pusher.
Config struct {
GCM GCM
Apns Apns
Queue Kafka
GracefulShutdownTimeout int
}

Kafka struct {
Brokers string
}

GCM struct {
Apps string
PingInterval int
PingTimeout int
MaxPendingMessages int
LogStatsInterval int
}

Apns struct {
Apps string
Certs map[string]Cert
}

Cert struct {
AuthKeyPath string
KeyID string
TeamID string
Topic string
}
)

// NewConfigAndViper returns a new Config object and the corresponding viper instance.
Expand All @@ -45,7 +63,7 @@ func NewConfigAndViper(configFile string) (*Config, *viper.Viper, error) {
return config, v, nil
}

func (c *Config) GetAppsArray() []string {
func (c *Config) GetGcmAppsArray() []string {
arr := strings.Split(c.GCM.Apps, ",")
res := make([]string, 0, len(arr))
for _, a := range arr {
Expand All @@ -55,6 +73,16 @@ func (c *Config) GetAppsArray() []string {
return res
}

func (c *Config) GetApnsAppsArray() []string {
arr := strings.Split(c.Apns.Apps, ",")
res := make([]string, 0, len(arr))
for _, a := range arr {
res = append(res, strings.TrimSpace(a))
}

return res
}

func decodeHookFunc() viper.DecoderConfigOption {
hooks := mapstructure.ComposeDecodeHookFunc(
StringToMapStringHookFunc(),
Expand Down
2 changes: 1 addition & 1 deletion config/docker_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ feedback:
topics: "com.games.test.feedbacks"
brokers: "kafka:9092"
cache:
requestTimeout: 100
requestTimeout: 3000
cleaningInterval: 20
stats:
reporters:
Expand Down
2 changes: 1 addition & 1 deletion config/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ feedback:
topics: "com.games.test.feedbacks"
brokers: "localhost:9941"
cache:
requestTimeout: 100
requestTimeout: 3000
cleaningInterval: 20
stats:
reporters:
Expand Down
Loading
Loading