Skip to content

Commit

Permalink
Retry wolt http (#7)
Browse files Browse the repository at this point in the history
* add retry

* tests and configuration for tetry

* 🐶
  • Loading branch information
oriser authored Dec 11, 2022
1 parent 483436f commit 25cdf5e
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 74 deletions.
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/hashicorp/go-retryablehttp v0.7.1
github.com/jmoiron/sqlx v1.3.4
github.com/mattn/go-sqlite3 v1.14.10
github.com/oriser/regroup v0.0.0-20201024192559-010c434ff8f3
github.com/paul-mannino/go-fuzzywuzzy v0.0.0-20200127021948-54652b135d0e
github.com/prometheus/common v0.10.0
github.com/slack-go/slack v0.10.3
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20211013171255-e13a2654a71e
Expand All @@ -23,9 +25,12 @@ require (
require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
Expand All @@ -34,7 +39,10 @@ require (
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
go.uber.org/atomic v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alexflint/go-filemutex v0.0.0-20171022225611-72bdc8eae2ae/go.mod h1:CgnQgUtFrFz9mxFNtED3jI5tLDjKlOM+oUF/sTk6ps0=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down Expand Up @@ -527,10 +529,15 @@ github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMW
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
Expand Down Expand Up @@ -789,6 +796,7 @@ github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7q
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc=
github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
Expand Down Expand Up @@ -829,6 +837,7 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/slack-go/slack v0.10.3 h1:kKYwlKY73AfSrtAk9UHWCXXfitudkDztNI9GYBviLxw=
github.com/slack-go/slack v0.10.3/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
Expand Down Expand Up @@ -1173,6 +1182,7 @@ golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210818153620-00dd8d7831e7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c h1:taxlMj0D/1sOAuv/CbSD+MMDof2vbyPTqz5FNYKpXt8=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -1407,6 +1417,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
4 changes: 2 additions & 2 deletions service/debt.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (h *Service) DebtWorker(ctx context.Context, orderID string) {
return
}

reminderInterval := time.NewTicker(h.debtReminderInterval)
reminderInterval := time.NewTicker(h.cfg.DebtReminderInterval)
defer reminderInterval.Stop()

for {
Expand Down Expand Up @@ -178,7 +178,7 @@ func (h *Service) addDebts(usersMap map[string]*userDomain.User, initiatedTransp
}

//goland:noinspection ALL
ctx, _ := context.WithTimeout(context.Background(), h.debtMaximumDuration) // nolint
ctx, _ := context.WithTimeout(context.Background(), h.cfg.DebtMaximumDuration) // nolint
go h.DebtWorker(ctx, orderID)

return nil
Expand Down
12 changes: 8 additions & 4 deletions service/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (h *Service) shouldHandleOrder() bool {
}

func (h *Service) waitForGroupProgress(g *wolt.Group) error {
timeoutTime := time.Now().Add(h.timeoutForReady)
timeoutTime := time.Now().Add(h.cfg.TimeoutForReady)

details, err := g.Details()
if err != nil {
Expand All @@ -233,7 +233,7 @@ func (h *Service) waitForGroupProgress(g *wolt.Group) error {
if time.Now().After(timeoutTime) {
return fmt.Errorf("timeout waiting for group to progress")
}
time.Sleep(h.waitBetweenStatusCheck)
time.Sleep(h.cfg.WaitBetweenStatusCheck)

details, err = g.Details()
if err != nil {
Expand Down Expand Up @@ -277,8 +277,12 @@ func (h *Service) calculateDeliveryRate(g *wolt.Group, details *wolt.OrderDetail

func (h *Service) getRateForGroup(receiver, groupID, messageID string) (GroupRate, error) {
g, err := wolt.NewGroupWithExistingID(wolt.WoltAddr{
BaseAddr: h.woltBaseAddr,
APIBaseAddr: h.woltApiAddr,
BaseAddr: h.cfg.WoltBaseAddr,
APIBaseAddr: h.cfg.WoltApiBaseAddr,
}, wolt.RetryConfig{
HTTPMaxRetries: h.cfg.WoltHTTPMaxRetryCount,
HTTPMinRetryDuration: h.cfg.WoltHTTPMinRetryDuration,
HTTPMaxRetryDuration: h.cfg.WoltHTTPMaxRetryDuration,
}, groupID)
if err != nil {
return GroupRate{}, fmt.Errorf("new existing group: %w", err)
Expand Down
49 changes: 20 additions & 29 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,29 @@ type EventNotification interface {
}

type Config struct {
TimeoutForReady time.Duration `env:"ORDER_READY_TIMEOUT" envDefault:"40m"`
TimeoutForDeliveryRate time.Duration `env:"GET_DELIVERY_RATE_TIMEOUT" envDefault:"10m"`
WaitBetweenStatusCheck time.Duration `env:"WAIT_BETWEEN_STATUS_CHECK" envDefault:"20s"`
DebtReminderInterval time.Duration `env:"DEBT_REMINDER_INTERVAL" envDefault:"3h"`
DebtMaximumDuration time.Duration `env:"DEBT_MAXIMUM_DURATION" envDefault:"24h"`
DontJoinAfter string `env:"DONT_JOIN_AFTER"`
DontJoinAfterTZ string `env:"DONT_JOIN_AFTER_TZ"`
WoltBaseAddr string `env:"WOLT_BASE_ADDR" envDefault:"https://wolt.com"`
WoltApiBaseAddr string `env:"WOLT_API_BASE_ADDR" envDefault:"https://restaurant-api.wolt.com"`
TimeoutForReady time.Duration `env:"ORDER_READY_TIMEOUT" envDefault:"40m"`
TimeoutForDeliveryRate time.Duration `env:"GET_DELIVERY_RATE_TIMEOUT" envDefault:"10m"`
WaitBetweenStatusCheck time.Duration `env:"WAIT_BETWEEN_STATUS_CHECK" envDefault:"20s"`
DebtReminderInterval time.Duration `env:"DEBT_REMINDER_INTERVAL" envDefault:"3h"`
DebtMaximumDuration time.Duration `env:"DEBT_MAXIMUM_DURATION" envDefault:"24h"`
DontJoinAfter string `env:"DONT_JOIN_AFTER"`
DontJoinAfterTZ string `env:"DONT_JOIN_AFTER_TZ"`
WoltBaseAddr string `env:"WOLT_BASE_ADDR" envDefault:"https://wolt.com"`
WoltApiBaseAddr string `env:"WOLT_API_BASE_ADDR" envDefault:"https://restaurant-api.wolt.com"`
WoltHTTPMaxRetryCount int `env:"WOLT_HTTP_MAX_RETRY_COUNT" envDefault:"5"`
WoltHTTPMinRetryDuration time.Duration `env:"WOLT_HTTP_MIN_RETRY_DURATION" envDefault:"1s"`
WoltHTTPMaxRetryDuration time.Duration `env:"WOLT_HTTP_MAX_RETRY_DURATION" envDefault:"30s"`
}

type Service struct {
timeoutForReady time.Duration
timeoutDeliveryRate time.Duration
waitBetweenStatusCheck time.Duration
cfg Config
eventNotification EventNotification
currentlyWorkingOrders sync.Map
userStore user.Store
debtStore debt.Store
debtReminderInterval time.Duration
debtMaximumDuration time.Duration
selfID string
dontJoinAfter time.Time
dontJoinAfterTZ *time.Location
woltBaseAddr string
woltApiAddr string
}

type ReactionAddRequest struct {
Expand Down Expand Up @@ -79,18 +76,12 @@ func New(cfg Config, userStore user.Store, debtStore debt.Store, selfID string,
}
}
return &Service{
timeoutForReady: cfg.TimeoutForReady,
timeoutDeliveryRate: cfg.TimeoutForDeliveryRate,
waitBetweenStatusCheck: cfg.WaitBetweenStatusCheck,
eventNotification: eventNotification,
userStore: userStore,
debtStore: debtStore,
debtReminderInterval: cfg.DebtReminderInterval,
debtMaximumDuration: cfg.DebtMaximumDuration,
selfID: selfID,
dontJoinAfter: dontJoinAfter,
dontJoinAfterTZ: dontJoinAfterTZ,
woltBaseAddr: cfg.WoltBaseAddr,
woltApiAddr: cfg.WoltApiBaseAddr,
cfg: cfg,
eventNotification: eventNotification,
userStore: userStore,
debtStore: debtStore,
selfID: selfID,
dontJoinAfter: dontJoinAfter,
dontJoinAfterTZ: dontJoinAfterTZ,
}, nil
}
30 changes: 19 additions & 11 deletions testing/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"path"
"sort"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -39,11 +40,15 @@ var (
)

const (
WaitForMessageTimeout = 20 * time.Second
OrderReadyTimeout = 10 * time.Second
WaitBetweenStatusCheck = 500 * time.Millisecond
DebtReminderInterval = 3 * time.Second
DebtMaximumDuration = 10 * time.Second
AdminSlackUserID = "ABC123"
MaxHttpAttempts = 10000 // A lot of attempts to make sure the request will succeed at last (we return 502 randomly for tests)
MinHttpRetryWait = time.Millisecond
MaxHttpRetryWait = 5 * time.Millisecond

DefaultNonBotUserID = "W012A3CDE" // From slack test package, it's not exposed, and it's constant
MessageChannel = "some-channel"
Expand Down Expand Up @@ -92,14 +97,17 @@ func initEnvs(t *testing.T, tdata testData) {
require.NoError(t, os.Setenv("DEBT_MAXIMUM_DURATION", DebtMaximumDuration.String()))
require.NoError(t, os.Setenv("WOLT_BASE_ADDR", "http://"+tdata.woltServer.Addr()))
require.NoError(t, os.Setenv("WOLT_API_BASE_ADDR", "http://"+tdata.woltServer.Addr()))
require.NoError(t, os.Setenv("WOLT_HTTP_MAX_RETRY_COUNT", strconv.Itoa(MaxHttpAttempts)))
require.NoError(t, os.Setenv("WOLT_HTTP_MIN_RETRY_DURATION", MinHttpRetryWait.String()))
require.NoError(t, os.Setenv("WOLT_HTTP_MAX_RETRY_DURATION", MaxHttpRetryWait.String()))

// main
require.NoError(t, os.Setenv("DB_LOCATION", path.Join(tmpDir, "db.sqlite")))
}

func initTest(t *testing.T) testData {
t.Helper()
woltServer := woltserver.NewWoltServer()
woltServer := woltserver.NewWoltServer(t)
t.Log("Starting test wolt server")
woltServer.Start()

Expand Down Expand Up @@ -359,7 +367,7 @@ func validateDebts(t *testing.T,
willRemainDebts = append(willRemainDebts, participant)
continue
}
_, err := WaitForOutboundSlackMessage(1*time.Second, tdata.slackServer,
_, err := WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer,
fmt.Sprintf("Reminder, you should pay %.2f nis to <@%s> for Wolt order ID %s.\n",
ratesMap[participant], participantIDsMapping[host], orderID),
participantIDsMapping[participant], "", ContainsMatch)
Expand All @@ -372,12 +380,12 @@ func validateDebts(t *testing.T,
assert.Equal(t, 200, resp.StatusCode)

// Checking messages sent to user and host
_, err = WaitForOutboundSlackMessage(1*time.Second, tdata.slackServer,
_, err = WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer,
fmt.Sprintf("OK! I removed your debt for order %s", orderID),
participantIDsMapping[participant], "", EqualMatch)
require.NoError(t, err)

_, err = WaitForOutboundSlackMessage(1*time.Second, tdata.slackServer,
_, err = WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer,
fmt.Sprintf("<@%s> marked himself as paid for order ID %s", participantIDsMapping[participant], orderID),
participantIDsMapping[host], "", EqualMatch)
require.NoError(t, err)
Expand All @@ -391,7 +399,7 @@ func validateDebts(t *testing.T,
t.Log("Waiting until debt timeout will reach")
time.Sleep(DebtMaximumDuration - 2*DebtReminderInterval)
if len(willRemainDebts) > 0 {
_, err := WaitForOutboundSlackMessage(1*time.Second, tdata.slackServer,
_, err := WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer,
fmt.Sprintf("I removed all debts for order ID %s because timeout has been reached", orderID),
participantIDsMapping[host], "", EqualMatch)
require.NoError(t, err)
Expand All @@ -409,7 +417,7 @@ func cancelDebts(t *testing.T,
require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)

_, err = WaitForOutboundSlackMessage(1*time.Second, tdata.slackServer,
_, err = WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer,
fmt.Sprintf("I removed all debts for order ID %s because the host requested to cancel debts tracking", orderID),
hostUser, "", EqualMatch)
require.NoError(t, err)
Expand Down Expand Up @@ -633,7 +641,7 @@ func TestSlackPurchaseGroup(t *testing.T) {
assert.Equal(t, 200, resp.StatusCode)

// Verifying joined message
_, err = WaitForOutboundSlackMessage(2*time.Second, tdata.slackServer, fmt.Sprintf(HelloPattern, orderShortID),
_, err = WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer, fmt.Sprintf(HelloPattern, orderShortID),
MessageChannel, timestamp, EqualMatch)
require.NoError(t, err)

Expand Down Expand Up @@ -669,7 +677,7 @@ func TestSlackPurchaseGroup(t *testing.T) {

// Validating the rates message
rates, ratesMessage := buildRatesMessage(t, order, expectedDelivery, participantIDsMapping)
msg, err := WaitForOutboundSlackMessage(3*time.Second, tdata.slackServer,
msg, err := WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer,
fmt.Sprintf("Rates for Wolt order ID %s", orderShortID),
MessageChannel, timestamp, ContainsMatch)
require.NoError(t, err)
Expand All @@ -685,14 +693,14 @@ func TestSlackPurchaseGroup(t *testing.T) {

if !tc.addHostToSlack {
// No debts mode
_, err = WaitForOutboundSlackMessage(2*time.Second, tdata.slackServer,
_, err = WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer,
fmt.Sprintf("I didn't find the user of the host (%s), I won't track debts for order %s", order.Host, orderShortID),
MessageChannel, timestamp, EqualMatch)
assert.NoError(t, err)
} else {
// Debt mode
// First, verifying debts message
_, err = WaitForOutboundSlackMessage(2*time.Second, tdata.slackServer,
_, err = WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer,
fmt.Sprintf("<@%s>, as the host, you can react with :x: to the rates message to cancel debts tracking for Wolt order ID %s",
participantIDsMapping[order.Host], orderShortID),
MessageChannel, timestamp, ContainsMatch)
Expand All @@ -703,7 +711,7 @@ func TestSlackPurchaseGroup(t *testing.T) {
// participant should exist and no "not found" message should be sent
continue
}
_, err = WaitForOutboundSlackMessage(2*time.Second, tdata.slackServer,
_, err = WaitForOutboundSlackMessage(WaitForMessageTimeout, tdata.slackServer,
fmt.Sprintf("I won't track %q payment because I can't find his user.", participant),
MessageChannel, timestamp, EqualMatch)
assert.NoError(t, err)
Expand Down
3 changes: 0 additions & 3 deletions testing/woltserver/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func (ws *WoltServer) joinByShortIDHandler(res http.ResponseWriter, req *http.Re
ws.writeError(res, http.StatusInternalServerError, err)
return
}
res.WriteHeader(http.StatusOK)
}

func (ws *WoltServer) joinByIDHandler(res http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -91,7 +90,6 @@ func (ws *WoltServer) orderDetailsHandler(res http.ResponseWriter, req *http.Req
ws.writeError(res, http.StatusInternalServerError, err)
return
}
res.WriteHeader(http.StatusOK)
}

func (ws *WoltServer) getVenueHandler(res http.ResponseWriter, req *http.Request) {
Expand All @@ -112,5 +110,4 @@ func (ws *WoltServer) getVenueHandler(res http.ResponseWriter, req *http.Request
ws.writeError(res, http.StatusInternalServerError, err)
return
}
res.WriteHeader(http.StatusOK)
}
Loading

0 comments on commit 25cdf5e

Please sign in to comment.