MCPcopy Index your code
hub / github.com/riverqueue/river / Test_Client_PilotUsage

Function Test_Client_PilotUsage

client_pilot_test.go:133–337  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

131}
132
133func Test_Client_PilotUsage(t *testing.T) {
134 t.Parallel()
135
136 ctx := context.Background()
137
138 setup := func(t *testing.T, configMutate func(*Config)) (*Client[pgx.Tx], *pilotSpy) {
139 t.Helper()
140
141 var (
142 dbPool = riversharedtest.DBPool(ctx, t)
143 driver = riverpgxv5.New(dbPool)
144 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
145 config = newTestConfig(t, schema)
146 )
147
148 if configMutate != nil {
149 configMutate(config)
150 }
151
152 pilot := &pilotSpy{}
153 pluginDriver := newDriverWithPlugin(t, dbPool)
154 pluginDriver.pilot = pilot
155
156 client, err := NewClient(pluginDriver, config)
157 require.NoError(t, err)
158
159 return client, pilot
160 }
161
162 withClientTx := func(t *testing.T, client *Client[pgx.Tx], callback func(tx pgx.Tx)) {
163 t.Helper()
164
165 exec := client.Driver().GetExecutor()
166 execTx, err := exec.Begin(ctx)
167 require.NoError(t, err)
168
169 committed := false
170 t.Cleanup(func() {
171 if !committed {
172 _ = execTx.Rollback(ctx)
173 }
174 })
175
176 tx := client.Driver().UnwrapTx(execTx)
177 callback(tx)
178
179 require.NoError(t, execTx.Commit(ctx))
180 committed = true
181 }
182
183 t.Run("InitUsesPilot", func(t *testing.T) {
184 t.Parallel()
185
186 client, pilot := setup(t, nil)
187 require.NotNil(t, client)
188 require.Equal(t, int64(1), pilot.jobCleanerQueuesExcludedCalls.Load())
189 require.Equal(t, int64(1), pilot.pilotInitCalls.Load())
190 })

Callers

nothing calls this directly

Calls 15

DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
WaitOrTimeoutFunction · 0.92
newDriverWithPluginFunction · 0.85
NewClientFunction · 0.85
NewPeriodicJobFunction · 0.85
PeriodicIntervalFunction · 0.85
AddWorkerFunction · 0.85
WorkFuncFunction · 0.85
DriverMethod · 0.80
CleanupMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…