(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func TestJobListWithJobs(t *testing.T) { |
| 76 | t.Parallel() |
| 77 | |
| 78 | ctx := context.Background() |
| 79 | |
| 80 | type testBundle struct { |
| 81 | baselineTime time.Time // baseline time frozen at now when setup is called |
| 82 | driver riverdriver.Driver[pgx.Tx] |
| 83 | exec riverdriver.Executor |
| 84 | jobs []*rivertype.JobRow |
| 85 | } |
| 86 | |
| 87 | setup := func(t *testing.T) *testBundle { |
| 88 | t.Helper() |
| 89 | |
| 90 | var ( |
| 91 | driver = riverpgxv5.New(nil) |
| 92 | tx = riverdbtest.TestTxPgx(ctx, t) |
| 93 | exec = driver.UnwrapExecutor(tx) |
| 94 | ) |
| 95 | |
| 96 | job1 := testfactory.Job(ctx, t, exec, &testfactory.JobOpts{Queue: ptrutil.Ptr("priority"), Priority: ptrutil.Ptr(1)}) |
| 97 | job2 := testfactory.Job(ctx, t, exec, &testfactory.JobOpts{EncodedArgs: []byte(`{"job_num": 2}`), Priority: ptrutil.Ptr(2)}) |
| 98 | job3 := testfactory.Job(ctx, t, exec, &testfactory.JobOpts{Metadata: []byte(`{"some_key": "some_value"}`), Priority: ptrutil.Ptr(3)}) |
| 99 | job4 := testfactory.Job(ctx, t, exec, &testfactory.JobOpts{State: ptrutil.Ptr(rivertype.JobStateRunning), Priority: ptrutil.Ptr(1)}) |
| 100 | job5 := testfactory.Job(ctx, t, exec, &testfactory.JobOpts{Kind: ptrutil.Ptr("alternate_kind"), Priority: ptrutil.Ptr(2)}) |
| 101 | |
| 102 | return &testBundle{ |
| 103 | baselineTime: time.Now(), |
| 104 | driver: driver, |
| 105 | exec: exec, |
| 106 | jobs: []*rivertype.JobRow{job1, job2, job3, job4, job5}, |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | type testListFunc func(jobs []*rivertype.JobRow, err error) |
| 111 | |
| 112 | execTest := func(ctx context.Context, t *testing.T, bundle *testBundle, params *JobListParams, testFunc testListFunc) { |
| 113 | t.Helper() |
| 114 | |
| 115 | listParams, err := JobMakeDriverParams(ctx, params, bundle.driver.SQLFragmentColumnIn) |
| 116 | require.NoError(t, err) |
| 117 | |
| 118 | t.Logf("testing JobList in Executor") |
| 119 | { |
| 120 | jobs, err := bundle.exec.JobList(ctx, listParams) |
| 121 | require.NoError(t, err) |
| 122 | testFunc(jobs, err) |
| 123 | } |
| 124 | |
| 125 | t.Logf("testing JobListTx") |
| 126 | { |
| 127 | // use a sub-transaction in case it's rolled back or errors: |
| 128 | execTx, err := bundle.exec.Begin(ctx) |
| 129 | require.NoError(t, err) |
| 130 | defer execTx.Rollback(ctx) |
| 131 | |
| 132 | jobs, err := execTx.JobList(ctx, listParams) |
nothing calls this directly
no test coverage detected
searching dependent graphs…