MCPcopy
hub / github.com/cubefs/cubefs / TestStatisticRotate

Function TestStatisticRotate

util/stat/statistic_test.go:148–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

146}
147
148func TestStatisticRotate(t *testing.T) {
149 time.Sleep(1 * time.Second)
150 DefaultStatInterval = 100 * time.Millisecond
151
152 tmpDir, err := os.MkdirTemp("", "")
153 require.NoError(t, err)
154
155 statLogModule := "test_stat"
156 fileSize := 1024 * 1024
157 timeOutUs := [MaxTimeoutLevel]uint32{100000, 500000, 1000000}
158 count := 10000 // every file is 1.12M
159 tickCnt := 5 // generate 50 files
160 expectLeftFileCount := 30
161
162 st, err := NewStatistic(tmpDir, statLogModule, int64(fileSize), timeOutUs, true)
163 st.headRoom = int64(countLeftSpace(st.logDir))/1024/1024 - int64(expectLeftFileCount)
164 require.NoError(t, err)
165 defer func() {
166 os.RemoveAll(st.logDir)
167 }()
168 defer ClearStat()
169
170 start := time.Now()
171 for {
172 if time.Since(start) > time.Second*time.Duration(tickCnt) {
173 break
174 }
175
176 for i := 0; i < count; i++ {
177 bgTime := BeginStat()
178 typename := "test" + strconv.Itoa(i)
179 EndStat(typename, nil, bgTime, 1)
180 }
181 time.Sleep(DefaultStatInterval)
182 }
183
184 time.Sleep(2 * time.Second)
185
186 items, err := os.ReadDir(st.logDir)
187 require.NoError(t, err)
188 for _, e := range items {
189 info, _ := e.Info()
190 t.Logf("got log files, e %s size = %v", e.Name(), info.Size())
191 }
192 // assert there are rotate files, and expire is vaild.
193 require.True(t, len(items) <= expectLeftFileCount+1)
194}

Callers

nothing calls this directly

Calls 11

NewStatisticFunction · 0.85
countLeftSpaceFunction · 0.85
ClearStatFunction · 0.85
BeginStatFunction · 0.85
EndStatFunction · 0.85
ReadDirMethod · 0.65
InfoMethod · 0.65
NameMethod · 0.65
SizeMethod · 0.65
RemoveAllMethod · 0.45
DurationMethod · 0.45

Tested by

no test coverage detected