(t *testing.T)
| 30 | } |
| 31 | |
| 32 | func TestNotifier(t *testing.T) { |
| 33 | t.Parallel() |
| 34 | |
| 35 | const ( |
| 36 | testTopic1 = "test_topic1" |
| 37 | testTopic2 = "test_topic2" |
| 38 | ) |
| 39 | |
| 40 | ctx := context.Background() |
| 41 | |
| 42 | type testBundle struct { |
| 43 | dbPool *pgxpool.Pool |
| 44 | exec riverdriver.Executor |
| 45 | schema string |
| 46 | } |
| 47 | |
| 48 | type testOpts struct { |
| 49 | dbPool *pgxpool.Pool // may be left nil for riversharedtest.DBPool |
| 50 | } |
| 51 | |
| 52 | setup := func(t *testing.T, opts *testOpts) (*Notifier, *testBundle) { |
| 53 | t.Helper() |
| 54 | |
| 55 | if opts == nil { |
| 56 | opts = &testOpts{} |
| 57 | } |
| 58 | |
| 59 | var ( |
| 60 | dbPool = cmp.Or(opts.dbPool, riversharedtest.DBPool(ctx, t)) |
| 61 | driver = riverpgxv5.New(dbPool) |
| 62 | schema = riverdbtest.TestSchema(ctx, t, driver, nil) |
| 63 | listener = driver.GetListener(&riverdriver.GetListenenerParams{Schema: schema}) |
| 64 | ) |
| 65 | |
| 66 | notifier := New(riversharedtest.BaseServiceArchetype(t), listener) |
| 67 | notifier.testSignals.Init(t) |
| 68 | |
| 69 | return notifier, &testBundle{ |
| 70 | dbPool: dbPool, |
| 71 | exec: driver.GetExecutor(), |
| 72 | schema: schema, |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | start := func(t *testing.T, notifier *Notifier) { |
| 77 | t.Helper() |
| 78 | |
| 79 | require.NoError(t, notifier.Start(ctx)) |
| 80 | t.Cleanup(notifier.Stop) |
| 81 | } |
| 82 | |
| 83 | t.Run("StartsAndStops", func(t *testing.T) { |
| 84 | t.Parallel() |
| 85 | |
| 86 | notifier, _ := setup(t, nil) |
| 87 | start(t, notifier) |
| 88 | |
| 89 | notifier.testSignals.ListeningBegin.WaitOrTimeout() |
nothing calls this directly
no test coverage detected
searching dependent graphs…