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

Function TestTasksTelemetry

coderd/telemetry/telemetry_test.go:756–1264  ·  view source on GitHub ↗

nolint: dupl // Test code is better WET than DRY.

(t *testing.T)

Source from the content-addressed store, hash-verified

754
755// nolint: dupl // Test code is better WET than DRY.
756func TestTasksTelemetry(t *testing.T) {
757 t.Parallel()
758
759 // Define a fixed reference time for deterministic testing.
760 now := time.Date(2025, 1, 15, 12, 0, 0, 0, time.UTC)
761
762 createAppStatus := func(ctx context.Context, db database.Store, wsID uuid.UUID, agentID, appID uuid.UUID, state database.WorkspaceAppStatusState, message string, createdAt time.Time) {
763 _, err := db.InsertWorkspaceAppStatus(ctx, database.InsertWorkspaceAppStatusParams{
764 ID: uuid.New(),
765 CreatedAt: createdAt,
766 WorkspaceID: wsID,
767 AgentID: agentID,
768 AppID: appID,
769 State: state,
770 Message: message,
771 })
772 require.NoError(t, err)
773 }
774
775 getApp := func(ctx context.Context, db database.Store, agentID uuid.UUID) database.WorkspaceApp {
776 apps, err := db.GetWorkspaceAppsByAgentID(ctx, agentID)
777 require.NoError(t, err)
778 require.NotEmpty(t, apps, "expected at least one app")
779 return apps[0]
780 }
781
782 type statusSpec struct {
783 state database.WorkspaceAppStatusState
784 message string
785 offset time.Duration
786 }
787
788 type buildSpec struct {
789 buildNumber int32
790 offset time.Duration
791 transition database.WorkspaceTransition
792 reason database.BuildReason
793 statuses []statusSpec // created after this build, using this build's app
794 }
795
796 tests := []struct {
797 name string
798
799 // Input: DB setup.
800 skipWorkspace bool
801 createdOffset time.Duration
802 buildOffset *time.Duration
803 extraBuilds []buildSpec
804 appStatuses []statusSpec
805
806 // Expected output.
807 expectEvent bool
808 lastPausedOffset *time.Duration
809 lastResumedOffset *time.Duration
810 pauseReason *string
811 resumeReason *string
812 idleDurationMS *int64
813 pausedDurationMS *int64

Callers

nothing calls this directly

Calls 15

createBuildMethod · 0.95
RefFunction · 0.92
ContextFunction · 0.92
NewDBFunction · 0.92
UserFunction · 0.92
OrganizationMemberFunction · 0.92
WorkspaceBuildFunction · 0.92
TemplateVersionFunction · 0.92
TaskFunction · 0.92
HashContentFunction · 0.92
CollectTasksFunction · 0.92
CollectTaskEventsFunction · 0.92

Tested by

no test coverage detected