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

Function TestSampleService

rivershared/startstop/start_stop_test.go:220–282  ·  view source on GitHub ↗

BaseStartStop tests that need specific internal implementation (like ones we can add to sampleService) to be able to verify.

(t *testing.T)

Source from the content-addressed store, hash-verified

218// BaseStartStop tests that need specific internal implementation (like ones we
219// can add to sampleService) to be able to verify.
220func TestSampleService(t *testing.T) {
221 t.Parallel()
222
223 ctx := context.Background()
224
225 type testBundle struct{}
226
227 setup := func(t *testing.T) (*sampleService, *testBundle) { //nolint:unparam
228 t.Helper()
229
230 return &sampleService{}, &testBundle{}
231 }
232
233 t.Run("StartedChannel", func(t *testing.T) {
234 t.Parallel()
235
236 service, _ := setup(t)
237
238 require.NoError(t, service.Start(ctx))
239 t.Cleanup(service.Stop)
240
241 riversharedtest.WaitOrTimeout(t, service.Started())
242 require.True(t, service.state)
243 })
244
245 t.Run("StartError", func(t *testing.T) {
246 t.Parallel()
247
248 service, _ := setup(t)
249 service.startErr = errors.New("error on start")
250
251 require.ErrorIs(t, service.Start(ctx), service.startErr)
252
253 riversharedtest.WaitOrTimeout(t, service.Started()) // start channel also closed on erroneous start
254 riversharedtest.WaitOrTimeout(t, service.Stopped())
255 })
256
257 t.Run("StartErrorThenSuccessfulRestart", func(t *testing.T) {
258 t.Parallel()
259
260 service, _ := setup(t)
261 service.startErr = errors.New("error on start")
262
263 // First start fails with our simulated error.
264 require.ErrorIs(t, service.Start(ctx), service.startErr)
265
266 riversharedtest.WaitOrTimeout(t, service.Started())
267 riversharedtest.WaitOrTimeout(t, service.Stopped())
268
269 // Clear error so the next start succeeds.
270 service.startErr = nil
271
272 // Second start should succeed despite the prior failure. Without the
273 // reset-on-failed-start logic in StartInit, isRunning would still be
274 // true and StartInit would return shouldStart=false, causing Start to
275 // return nil without actually starting the service.
276 require.NoError(t, service.Start(ctx))
277 t.Cleanup(service.Stop)

Callers

nothing calls this directly

Calls 7

WaitOrTimeoutFunction · 0.92
CleanupMethod · 0.80
HelperMethod · 0.65
RunMethod · 0.65
StartMethod · 0.65
StartedMethod · 0.65
StoppedMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…