MCPcopy Create free account
hub / github.com/riverqueue/river / exerciseNotification

Function exerciseNotification

riverdriver/riverdrivertest/notification.go:13–64  ·  view source on GitHub ↗
(ctx context.Context, t *testing.T, executorWithTx func(ctx context.Context, t *testing.T) (riverdriver.Executor, riverdriver.Driver[TTx]))

Source from the content-addressed store, hash-verified

11)
12
13func exerciseNotification[TTx any](ctx context.Context, t *testing.T, executorWithTx func(ctx context.Context, t *testing.T) (riverdriver.Executor, riverdriver.Driver[TTx])) {
14 t.Helper()
15
16 t.Run("NotificationDeleteBefore", func(t *testing.T) {
17 t.Parallel()
18
19 exec, driver := executorWithTx(ctx, t)
20
21 insertQuery := `
22 INSERT INTO river_notification (created_at, payload, topic)
23 VALUES
24 ($1, $2, $3),
25 ($4, $5, $6),
26 ($7, $8, $9)
27 `
28 if driver.DatabaseName() == riverdriver.DatabaseNameSQLite {
29 insertQuery = `
30 INSERT INTO river_notification (created_at, payload, topic)
31 VALUES
32 (?, ?, ?),
33 (?, ?, ?),
34 (?, ?, ?)
35 `
36 }
37 createdAt := func(t time.Time) any { return t }
38 if driver.DatabaseName() == riverdriver.DatabaseNameSQLite {
39 // Keep this in the same format that the SQLite driver uses for
40 // CreatedAtHorizon so SQLite's text comparison stays chronological.
41 createdAt = func(t time.Time) any {
42 const sqliteFormat = "2006-01-02 15:04:05.999"
43 return t.UTC().Round(time.Millisecond).Format(sqliteFormat)
44 }
45 }
46
47 now := time.Now().UTC()
48 require.NoError(t, exec.Exec(ctx, insertQuery,
49 createdAt(now.Add(-2*time.Hour)), "old_payload_1", "topic",
50 createdAt(now.Add(-61*time.Minute)), "old_payload_2", "topic",
51 createdAt(now.Add(-30*time.Minute)), "new_payload", "topic",
52 ))
53
54 numDeleted, err := exec.NotificationDeleteBefore(ctx, &riverdriver.NotificationDeleteBeforeParams{
55 CreatedAtHorizon: now.Add(-time.Hour),
56 })
57 require.NoError(t, err)
58 require.Equal(t, 2, numDeleted)
59
60 var count int
61 require.NoError(t, exec.QueryRow(ctx, "SELECT count(*) FROM river_notification").Scan(&count))
62 require.Equal(t, 1, count)
63 })
64}

Callers 1

ExerciseFunction · 0.85

Calls 9

HelperMethod · 0.65
RunMethod · 0.65
DatabaseNameMethod · 0.65
NowMethod · 0.65
ExecMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…