MCPcopy Index your code
hub / github.com/coder/coder / newDetectorTestEnv

Function newDetectorTestEnv

coderd/jobreaper/detector_test.go:48–66  ·  view source on GitHub ↗

newDetectorTestEnv creates a new test environment with a started detector.

(ctx context.Context, t *testing.T)

Source from the content-addressed store, hash-verified

46
47// newDetectorTestEnv creates a new test environment with a started detector.
48func newDetectorTestEnv(ctx context.Context, t *testing.T) *detectorTestEnv {
49 t.Helper()
50 db, ps := dbtestutil.NewDB(t)
51 log := testutil.Logger(t)
52 tickCh := make(chan time.Time)
53 statsCh := make(chan jobreaper.Stats)
54
55 detector := jobreaper.New(ctx, wrapDBAuthz(db, log), ps, log, tickCh).WithStatsChannel(statsCh)
56 detector.Start()
57
58 return &detectorTestEnv{
59 t: t,
60 DB: db,
61 Pubsub: ps,
62 detector: detector,
63 tickCh: tickCh,
64 statsCh: statsCh,
65 }
66}
67
68// tick sends a tick with the given time and returns the stats from the
69// detector run. It respects context cancellation to avoid blocking forever

Calls 7

NewDBFunction · 0.92
LoggerFunction · 0.92
NewFunction · 0.92
wrapDBAuthzFunction · 0.85
HelperMethod · 0.65
StartMethod · 0.65
WithStatsChannelMethod · 0.45

Tested by

no test coverage detected