(t *testing.T)
| 266 | } |
| 267 | |
| 268 | func TestBaseAppLoggerWrites(t *testing.T) { |
| 269 | t.Parallel() |
| 270 | |
| 271 | app, _ := tests.NewTestApp() |
| 272 | defer app.Cleanup() |
| 273 | |
| 274 | // reset |
| 275 | if err := app.DeleteOldLogs(time.Now()); err != nil { |
| 276 | t.Fatal(err) |
| 277 | } |
| 278 | |
| 279 | const logsThreshold = 200 |
| 280 | |
| 281 | totalLogs := func(app core.App, t *testing.T) int { |
| 282 | var total int |
| 283 | |
| 284 | err := app.LogQuery().Select("count(*)").Row(&total) |
| 285 | if err != nil { |
| 286 | t.Fatalf("Failed to fetch total logs: %v", err) |
| 287 | } |
| 288 | |
| 289 | return total |
| 290 | } |
| 291 | |
| 292 | t.Run("disabled logs retention", func(t *testing.T) { |
| 293 | app.Settings().Logs.MaxDays = 0 |
| 294 | |
| 295 | for i := 0; i < logsThreshold+1; i++ { |
| 296 | app.Logger().Error("test") |
| 297 | } |
| 298 | |
| 299 | if total := totalLogs(app, t); total != 0 { |
| 300 | t.Fatalf("Expected no logs, got %d", total) |
| 301 | } |
| 302 | }) |
| 303 | |
| 304 | t.Run("test batch logs writes", func(t *testing.T) { |
| 305 | app.Settings().Logs.MaxDays = 1 |
| 306 | |
| 307 | for i := 0; i < logsThreshold-1; i++ { |
| 308 | app.Logger().Error("test") |
| 309 | } |
| 310 | |
| 311 | if total := totalLogs(app, t); total != 0 { |
| 312 | t.Fatalf("Expected no logs, got %d", total) |
| 313 | } |
| 314 | |
| 315 | // should trigger batch write |
| 316 | app.Logger().Error("test") |
| 317 | |
| 318 | // should be added for the next batch write |
| 319 | app.Logger().Error("test") |
| 320 | |
| 321 | if total := totalLogs(app, t); total != logsThreshold { |
| 322 | t.Fatalf("Expected %d logs, got %d", logsThreshold, total) |
| 323 | } |
| 324 | |
| 325 | // wait for ~3 secs to check the timer trigger |
nothing calls this directly
no test coverage detected
searching dependent graphs…