forked from docker/buildx
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request docker#2323 from jsternberg/build-idle-time-metric
metrics: measure idle time during builds
- Loading branch information
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package progress | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCalculateIdleTime(t *testing.T) { | ||
for _, tt := range []struct { | ||
started []int64 | ||
completed []int64 | ||
ms int64 | ||
}{ | ||
{ | ||
started: []int64{0, 1, 3}, | ||
completed: []int64{2, 10, 5}, | ||
ms: 0, | ||
}, | ||
{ | ||
started: []int64{0, 3}, | ||
completed: []int64{2, 5}, | ||
ms: 1, | ||
}, | ||
{ | ||
started: []int64{3, 0, 7}, | ||
completed: []int64{5, 2, 10}, | ||
ms: 3, | ||
}, | ||
} { | ||
started := unixMillis(tt.started...) | ||
completed := unixMillis(tt.completed...) | ||
|
||
actual := int64(calculateIdleTime(started, completed) / time.Millisecond) | ||
assert.Equal(t, tt.ms, actual) | ||
} | ||
} | ||
|
||
func unixMillis(ts ...int64) []time.Time { | ||
times := make([]time.Time, len(ts)) | ||
for i, ms := range ts { | ||
times[i] = time.UnixMilli(ms) | ||
} | ||
return times | ||
} |