github.com/argoproj/argo-cd@v1.8.7/util/stats/stats_test.go (about)

     1  package stats
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestTimingStats(t *testing.T) {
    11  	start := time.Now()
    12  	now = func() time.Time {
    13  		return start
    14  	}
    15  	defer func() {
    16  		now = time.Now
    17  	}()
    18  	ts := NewTimingStats()
    19  	now = func() time.Time {
    20  		return start.Add(100 * time.Millisecond)
    21  	}
    22  	ts.AddCheckpoint("checkpoint-1")
    23  	now = func() time.Time {
    24  		return start.Add(300 * time.Millisecond)
    25  	}
    26  	ts.AddCheckpoint("checkpoint-2")
    27  	timings := ts.Timings()
    28  	assert.Len(t, timings, 2)
    29  	assert.Equal(t, 100*time.Millisecond, timings["checkpoint-1"])
    30  	assert.Equal(t, 200*time.Millisecond, timings["checkpoint-2"])
    31  }