Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test: use barrier inTestInflightDispatchesMetric#15107

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 1 commit intomainfromfix-flaky-metrics
Oct 16, 2024
Merged
Changes fromall commits
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
35 changes: 22 additions & 13 deletionscoderd/notifications/metrics_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ package notifications_test
import (
"context"
"strconv"
"sync"
"testing"
"time"

Expand DownExpand Up@@ -317,10 +318,12 @@ func TestInflightDispatchesMetric(t *testing.T) {
})

handler := &fakeHandler{}
// Delayer will delay all dispatches by 2x fetch intervals to ensure we catch the requests inflight.
delayer := newDelayingHandler(cfg.FetchInterval.Value()*2, handler)
const msgCount = 2

// Barrier handler will wait until all notification messages are in-flight.
barrier := newBarrierHandler(msgCount, handler)
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{
method:delayer,
method:barrier,
})

enq, err := notifications.NewStoreEnqueuer(cfg, api.Database, defaultHelpers(), api.Logger.Named("enqueuer"), quartz.NewReal())
Expand All@@ -329,7 +332,6 @@ func TestInflightDispatchesMetric(t *testing.T) {
user := createSampleUser(t, api.Database)

// WHEN: notifications are enqueued which will succeed (and be delayed during dispatch)
const msgCount = 2
for i := 0; i < msgCount; i++ {
_, err = enq.Enqueue(ctx, user.ID, template, map[string]string{"type": "success", "i": strconv.Itoa(i)}, "test")
require.NoError(t, err)
Expand All@@ -343,6 +345,10 @@ func TestInflightDispatchesMetric(t *testing.T) {
return promtest.ToFloat64(metrics.InflightDispatches.WithLabelValues(string(method), template.String())) == msgCount
}, testutil.WaitShort, testutil.IntervalFast)

for i := 0; i < msgCount; i++ {
barrier.wg.Done()
}

// Wait until the handler has dispatched the given notifications.
require.Eventually(t, func() bool {
handler.mu.RLock()
Expand DownExpand Up@@ -493,27 +499,30 @@ func (u *updateSignallingInterceptor) BulkMarkNotificationMessagesFailed(ctx con
return u.Store.BulkMarkNotificationMessagesFailed(ctx, arg)
}

typedelayingHandler struct {
typebarrierHandler struct {
h notifications.Handler

delay time.Duration
wg *sync.WaitGroup
}

func newDelayingHandler(delay time.Duration, handler notifications.Handler) *delayingHandler {
return &delayingHandler{
delay: delay,
h: handler,
func newBarrierHandler(total int, handler notifications.Handler) *barrierHandler {
var wg sync.WaitGroup
wg.Add(total)

return &barrierHandler{
h: handler,
wg: &wg,
}
}

func (d *delayingHandler) Dispatcher(payload types.MessagePayload, title, body string) (dispatch.DeliveryFunc, error) {
deliverFn, err :=d.h.Dispatcher(payload, title, body)
func (bh *barrierHandler) Dispatcher(payload types.MessagePayload, title, body string) (dispatch.DeliveryFunc, error) {
deliverFn, err :=bh.h.Dispatcher(payload, title, body)
if err != nil {
return nil, err
}

return func(ctx context.Context, msgID uuid.UUID) (retryable bool, err error) {
time.Sleep(d.delay)
bh.wg.Wait()

return deliverFn(ctx, msgID)
}, nil
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp