cubefs
1// Copyright 2022 The CubeFS Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12// implied. See the License for the specific language governing
13// permissions and limitations under the License.
14
15package stat16
17import (18"os"19"path"20"testing"21"time"22
23"github.com/cubefs/cubefs/util/errors"24)
25
26func TestStatistic(t *testing.T) {27DefaultStatInterval = 1 * time.Second28
29statLogPath := "./"30statLogSize := 2000000031statLogModule := "TestStatistic"32timeOutUs := [MaxTimeoutLevel]uint32{100000, 500000, 1000000}33
34_, err := NewStatistic(statLogPath, statLogModule, int64(statLogSize), timeOutUs, true)35if err != nil {36t.Fatal(err)37}38defer os.RemoveAll(path.Join(statLogPath, statLogModule))39defer ClearStat()40
41bgTime := BeginStat()42EndStat("test1", nil, bgTime, 1)43time.Sleep(time.Second)44err = errors.New("EIO")45EndStat("test2", err, bgTime, 100)46time.Sleep(3 * time.Second)47}
48