(t *testing.T)
| 21 | ) |
| 22 | |
| 23 | func resourceMonitorAPI(t *testing.T) (*agentapi.ResourcesMonitoringAPI, database.User, *quartz.Mock, *notificationstest.FakeEnqueuer) { |
| 24 | t.Helper() |
| 25 | |
| 26 | db, _ := dbtestutil.NewDB(t) |
| 27 | user := dbgen.User(t, db, database.User{}) |
| 28 | org := dbgen.Organization(t, db, database.Organization{}) |
| 29 | template := dbgen.Template(t, db, database.Template{ |
| 30 | OrganizationID: org.ID, |
| 31 | CreatedBy: user.ID, |
| 32 | }) |
| 33 | templateVersion := dbgen.TemplateVersion(t, db, database.TemplateVersion{ |
| 34 | TemplateID: uuid.NullUUID{Valid: true, UUID: template.ID}, |
| 35 | OrganizationID: org.ID, |
| 36 | CreatedBy: user.ID, |
| 37 | }) |
| 38 | workspace := dbgen.Workspace(t, db, database.WorkspaceTable{ |
| 39 | OrganizationID: org.ID, |
| 40 | TemplateID: template.ID, |
| 41 | OwnerID: user.ID, |
| 42 | }) |
| 43 | job := dbgen.ProvisionerJob(t, db, nil, database.ProvisionerJob{ |
| 44 | Type: database.ProvisionerJobTypeWorkspaceBuild, |
| 45 | }) |
| 46 | build := dbgen.WorkspaceBuild(t, db, database.WorkspaceBuild{ |
| 47 | JobID: job.ID, |
| 48 | WorkspaceID: workspace.ID, |
| 49 | TemplateVersionID: templateVersion.ID, |
| 50 | }) |
| 51 | resource := dbgen.WorkspaceResource(t, db, database.WorkspaceResource{ |
| 52 | JobID: build.JobID, |
| 53 | }) |
| 54 | agent := dbgen.WorkspaceAgent(t, db, database.WorkspaceAgent{ |
| 55 | ResourceID: resource.ID, |
| 56 | }) |
| 57 | |
| 58 | notifyEnq := ¬ificationstest.FakeEnqueuer{} |
| 59 | clock := quartz.NewMock(t) |
| 60 | |
| 61 | return &agentapi.ResourcesMonitoringAPI{ |
| 62 | AgentID: agent.ID, |
| 63 | WorkspaceID: workspace.ID, |
| 64 | Clock: clock, |
| 65 | Database: db, |
| 66 | NotificationsEnqueuer: notifyEnq, |
| 67 | Config: resourcesmonitor.Config{ |
| 68 | NumDatapoints: 20, |
| 69 | CollectionInterval: 10 * time.Second, |
| 70 | |
| 71 | Alert: resourcesmonitor.AlertConfig{ |
| 72 | MinimumNOKsPercent: 20, |
| 73 | ConsecutiveNOKsPercent: 50, |
| 74 | }, |
| 75 | }, |
| 76 | Debounce: 1 * time.Minute, |
| 77 | }, user, clock, notifyEnq |
| 78 | } |
| 79 | |
| 80 | func TestMemoryResourceMonitorDebounce(t *testing.T) { |
no test coverage detected