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

Function TestMemoryResourceMonitor

coderd/agentapi/resources_monitoring_test.go:208–328  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

206}
207
208func TestMemoryResourceMonitor(t *testing.T) {
209 t.Parallel()
210
211 tests := []struct {
212 name string
213 memoryUsage []int64
214 memoryTotal int64
215 previousState database.WorkspaceAgentMonitorState
216 expectState database.WorkspaceAgentMonitorState
217 shouldNotify bool
218 }{
219 {
220 name: "WhenOK/NeverExceedsThreshold",
221 memoryUsage: []int64{2, 3, 2, 4, 2, 3, 2, 1, 2, 3, 4, 4, 1, 2, 3, 1, 2},
222 memoryTotal: 10,
223 previousState: database.WorkspaceAgentMonitorStateOK,
224 expectState: database.WorkspaceAgentMonitorStateOK,
225 shouldNotify: false,
226 },
227 {
228 name: "WhenOK/ShouldStayInOK",
229 memoryUsage: []int64{9, 3, 2, 4, 2, 3, 2, 1, 2, 3, 4, 4, 1, 2, 3, 1, 2},
230 memoryTotal: 10,
231 previousState: database.WorkspaceAgentMonitorStateOK,
232 expectState: database.WorkspaceAgentMonitorStateOK,
233 shouldNotify: false,
234 },
235 {
236 name: "WhenOK/ConsecutiveExceedsThreshold",
237 memoryUsage: []int64{2, 3, 2, 4, 2, 3, 2, 1, 2, 3, 4, 4, 1, 8, 9, 8, 9},
238 memoryTotal: 10,
239 previousState: database.WorkspaceAgentMonitorStateOK,
240 expectState: database.WorkspaceAgentMonitorStateNOK,
241 shouldNotify: true,
242 },
243 {
244 name: "WhenOK/MinimumExceedsThreshold",
245 memoryUsage: []int64{2, 8, 2, 9, 2, 8, 2, 9, 2, 8, 4, 9, 1, 8, 2, 8, 9},
246 memoryTotal: 10,
247 previousState: database.WorkspaceAgentMonitorStateOK,
248 expectState: database.WorkspaceAgentMonitorStateNOK,
249 shouldNotify: true,
250 },
251 {
252 name: "WhenNOK/NeverExceedsThreshold",
253 memoryUsage: []int64{2, 3, 2, 4, 2, 3, 2, 1, 2, 3, 4, 4, 1, 2, 3, 1, 2},
254 memoryTotal: 10,
255 previousState: database.WorkspaceAgentMonitorStateNOK,
256 expectState: database.WorkspaceAgentMonitorStateOK,
257 shouldNotify: false,
258 },
259 {
260 name: "WhenNOK/ShouldStayInNOK",
261 memoryUsage: []int64{9, 3, 2, 4, 2, 3, 2, 1, 2, 3, 4, 4, 1, 2, 3, 1, 2},
262 memoryTotal: 10,
263 previousState: database.WorkspaceAgentMonitorStateNOK,
264 expectState: database.WorkspaceAgentMonitorStateNOK,
265 shouldNotify: false,

Callers

nothing calls this directly

Calls 12

WithTemplateIDFunction · 0.92
resourceMonitorAPIFunction · 0.85
InitMonitorsMethod · 0.80
SentMethod · 0.80
RunMethod · 0.65
AddMethod · 0.65
NewMethod · 0.65
SetMethod · 0.65
LenMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected