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

Function Test_RecordedOutput

recorded_output_test.go:19–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func Test_RecordedOutput(t *testing.T) {
20 t.Parallel()
21 ctx := context.Background()
22
23 type JobArgs struct {
24 testutil.JobArgsReflectKind[JobArgs]
25 }
26
27 type myOutput struct {
28 Message string `json:"message"`
29 }
30
31 type testBundle struct {
32 dbPool *pgxpool.Pool
33 schema string
34 }
35
36 setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) {
37 t.Helper()
38
39 var (
40 dbPool = riversharedtest.DBPool(ctx, t)
41 driver = riverpgxv5.New(dbPool)
42 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
43 config = newTestConfig(t, schema)
44 client = newTestClient(t, dbPool, config)
45 )
46
47 t.Cleanup(func() { require.NoError(t, client.Stop(ctx)) })
48
49 return client, &testBundle{
50 dbPool: dbPool,
51 schema: schema,
52 }
53 }
54
55 t.Run("ValidOutput", func(t *testing.T) {
56 t.Parallel()
57
58 client, _ := setup(t)
59
60 validOutput := myOutput{Message: "it worked"}
61 expectedOutput := `{"output":{"message":"it worked"}}`
62 AddWorker(client.config.Workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error {
63 return RecordOutput(ctx, validOutput)
64 }))
65
66 subChan := subscribe(t, client)
67 startClient(ctx, t, client)
68
69 insertRes, err := client.Insert(ctx, JobArgs{}, nil)
70 require.NoError(t, err)
71
72 event := riversharedtest.WaitOrTimeout(t, subChan)
73 require.Equal(t, EventKindJobCompleted, event.Kind)
74 require.JSONEq(t, expectedOutput, string(event.Job.Metadata))
75
76 jobFromDB, err := client.JobGet(ctx, insertRes.Job.ID)

Callers

nothing calls this directly

Calls 15

DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
WaitOrTimeoutFunction · 0.92
newTestClientFunction · 0.85
AddWorkerFunction · 0.85
WorkFuncFunction · 0.85
RecordOutputFunction · 0.85
CleanupMethod · 0.80
InsertMethod · 0.80
JobGetMethod · 0.80
newTestConfigFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…