Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 00633a1

Browse files
committed
Small fixes
Signed-off-by: Danny Kopping <[email protected]>
1 parent 6602682 commit 00633a1

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

coderd/notifications/metrics_test.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ import (
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
1616

17-
"cdr.dev/slog"
18-
"cdr.dev/slog/sloggers/slogtest"
1917
"github.com/coder/serpent"
2018

2119
"github.com/coder/coder/v2/coderd/database"
22-
"github.com/coder/coder/v2/coderd/database/dbmem"
2320
"github.com/coder/coder/v2/coderd/database/dbtestutil"
2421
"github.com/coder/coder/v2/coderd/notifications"
2522
"github.com/coder/coder/v2/coderd/notifications/dispatch"
@@ -206,9 +203,7 @@ func TestPendingUpdatesMetric(t *testing.T) {
206203
t.Parallel()
207204

208205
// SETUP
209-
ctx := context.Background()
210-
store := dbmem.New()
211-
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
206+
ctx, logger, store := setupInMemory(t)
212207

213208
reg := prometheus.NewRegistry()
214209
metrics := notifications.NewMetrics(reg)
@@ -282,9 +277,7 @@ func TestInflightDispatchesMetric(t *testing.T) {
282277
t.Parallel()
283278

284279
// SETUP
285-
ctx := context.Background()
286-
store := dbmem.New()
287-
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Leveled(slog.LevelDebug)
280+
ctx, logger, store := setupInMemory(t)
288281

289282
reg := prometheus.NewRegistry()
290283
metrics := notifications.NewMetrics(reg)
@@ -304,8 +297,8 @@ func TestInflightDispatchesMetric(t *testing.T) {
304297
t.Cleanup(func() {
305298
assert.NoError(t, mgr.Stop(ctx))
306299
})
307-
handler := &fakeHandler{}
308300

301+
handler := &fakeHandler{}
309302
// Delayer will delay all dispatches by 2x fetch intervals to ensure we catch the requests inflight.
310303
delayer := newDelayingHandler(cfg.FetchInterval.Value()*2, handler)
311304
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{
@@ -317,26 +310,27 @@ func TestInflightDispatchesMetric(t *testing.T) {
317310

318311
user := createSampleUser(t, store)
319312

320-
// WHEN: 2 notifications are enqueued which will both succeed
321-
_, err = enq.Enqueue(ctx, user.ID, template, map[string]string{"type": "success"}, "test")
322-
require.NoError(t, err)
323-
_, err = enq.Enqueue(ctx, user.ID, template, map[string]string{"type": "success"}, "test2")
324-
require.NoError(t, err)
313+
// WHEN: notifications are enqueued which will succeed (and be delayed during dispatch)
314+
const msgCount = 2
315+
for i := 0; i < msgCount; i++ {
316+
_, err = enq.Enqueue(ctx, user.ID, template, map[string]string{"type": "success"}, "test")
317+
require.NoError(t, err)
318+
}
325319

326320
mgr.Run(ctx)
327321

328322
// THEN:
329-
// Ensure we see the dispatches of the two messages inflight.
323+
// Ensure we see the dispatches of the messages inflight.
330324
require.Eventually(t, func() bool {
331-
return promtest.ToFloat64(metrics.InflightDispatches.WithLabelValues(string(method), template.String())) == 2
325+
return promtest.ToFloat64(metrics.InflightDispatches.WithLabelValues(string(method), template.String())) == msgCount
332326
}, testutil.WaitShort, testutil.IntervalFast)
333327

334328
// Wait until the handler has dispatched the given notifications.
335329
require.Eventually(t, func() bool {
336330
handler.mu.RLock()
337331
defer handler.mu.RUnlock()
338332

339-
return len(handler.succeeded) == 2
333+
return len(handler.succeeded) == msgCount
340334
}, testutil.WaitShort, testutil.IntervalFast)
341335

342336
// Wait for the updates to be synced and the metric to reflect that.

coderd/notifications/notifier.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ func (n *notifier) run(ctx context.Context, success chan<- dispatchResult, failu
103103

104104
// ensureRunning checks if notifier is not paused.
105105
func (n *notifier) ensureRunning(ctx context.Context) (bool, error) {
106-
n.log.Debug(ctx, "check if notifier is paused")
107-
108106
settingsJSON, err := n.store.GetNotificationsSettings(ctx)
109107
if err != nil {
110108
return false, xerrors.Errorf("get notifications settings: %w", err)

0 commit comments

Comments
 (0)