(t *testing.T)
| 206 | } |
| 207 | |
| 208 | func 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, |
nothing calls this directly
no test coverage detected