MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestLogRotationInterval

Function TestLogRotationInterval

base/logging_test.go:62–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

60}
61
62func TestLogRotationInterval(t *testing.T) {
63 LongRunningTest(t)
64
65 // override min rotation interval for testing
66 originalMinRotationInterval := minLogRotationInterval
67 minLogRotationInterval = time.Millisecond * 10
68 defer func() { minLogRotationInterval = originalMinRotationInterval }()
69
70 rotationInterval := time.Millisecond * 100
71 config := &FileLoggerConfig{
72 Enabled: Ptr(true),
73 CollationBufferSize: Ptr(0),
74 Rotation: logRotationConfig{
75 RotationInterval: NewConfigDuration(rotationInterval),
76 compress: Ptr(false),
77 },
78 }
79
80 logPath := lumberjackTempDir(t)
81 countBefore := numFilesInDir(t, logPath, false)
82 t.Logf("countBefore: %d", countBefore)
83
84 ctx := TestCtx(t)
85 fl, err := NewFileLogger(ctx, config, LevelTrace, "test", logPath, 0, nil, nil)
86 require.NoError(t, err)
87 defer func() {
88 assert.NoError(t, fl.Close())
89 // Wait for Lumberjack to finish its async log compression work
90 // we have no way of waiting for this to finish, or even stopping the millRun() process inside Lumberjack.
91 time.Sleep(time.Second)
92 }()
93
94 fl.logf("test 1")
95 countAfter1 := numFilesInDir(t, logPath, false)
96 t.Logf("countAfter1: %d", countAfter1)
97 assert.Greater(t, countAfter1, countBefore)
98
99 time.Sleep(rotationInterval * 5)
100 countAfterSleep := numFilesInDir(t, logPath, false)
101 t.Logf("countAfterSleep: %d", countAfterSleep)
102 assert.Greater(t, countAfterSleep, countAfter1)
103
104 fl.logf("test 2")
105 countAfter2 := numFilesInDir(t, logPath, false)
106 t.Logf("countAfter2: %d", countAfter2)
107 assert.GreaterOrEqual(t, countAfter2, countAfterSleep)
108
109}
110
111// Benchmark the time it takes to write x bytes of data to a logger, and optionally rotate and compress it.
112func BenchmarkLogRotation(b *testing.B) {

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
logfMethod · 0.95
LongRunningTestFunction · 0.85
PtrFunction · 0.85
NewConfigDurationFunction · 0.85
lumberjackTempDirFunction · 0.85
numFilesInDirFunction · 0.85
TestCtxFunction · 0.85
NewFileLoggerFunction · 0.85
LogfMethod · 0.45

Tested by

no test coverage detected