Repository navigation
Expand file tree
/
Copy pathprogress_test.go
More file actions
96 lines (92 loc) · 3.23 KB
/
Copy pathprogress_test.go
File metadata and controls
96 lines (92 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package main
import (
"strings"
"testing"
"time"
)
func TestProgressLine(t *testing.T) {
for _, tt := range []struct {
name string
p progressSnapshot
want []string
}{
{
name: "discovering",
p: progressSnapshot{Phase: phaseDiscovering, PackagesDiscovered: 123, PackagesTotal: 45, Elapsed: 2 * time.Second},
want: []string{"discovering", "123 pkgs matched", "45 with tests", "2s"},
},
{
name: "building",
p: progressSnapshot{
Phase: phaseBuilding, PackagesDiscovered: 200, PackagesBuilt: 30,
PackagesCached: 12, PackagesTotal: 80,
},
want: []string{"building", "80/200 test pkgs", "30/80 built", "12 cached, 40.0%"},
},
{
name: "listing",
p: progressSnapshot{Phase: phaseListing, PackagesDiscovered: 200, PackagesListed: 40, PackagesTotal: 80, TestsTotal: 456},
want: []string{"listing", "200 pkgs matched", "80 with tests", "40/80 test pkgs listed", "456 tests found"},
},
{
name: "testing partial cache",
p: progressSnapshot{
Phase: phaseTesting, PackagesDone: 12, PackagesTotal: 80,
TestsDone: 345, TestsTotal: 1000, TestsRunning: 4,
TestsFlaky: 2, CacheEnabled: true, CacheChecks: 400, CacheHits: 300,
ETAAvailable: true, TestETA: 12 * time.Second, ETAUnknown: 7, ETAMedian: 40 * time.Millisecond,
},
want: []string{"testing", "12/80 test pkgs", "345/1000 tests", "4 running", "2 flaky", "cache hits 300/400 (75.0%)", "ETA 12s", "7 unknown at <1s median"},
},
{
name: "done cache off",
p: progressSnapshot{Phase: phaseDone, PackagesDone: 2, PackagesTotal: 2, TestsDone: 10, TestsTotal: 10},
want: []string{"done", "2/2 test pkgs", "10/10 tests", "0 running", "cache off"},
},
{
name: "build only done",
p: progressSnapshot{
Phase: phaseDone, BuildOnly: true, PackagesDiscovered: 300,
PackagesTotal: 282, PackagesBuilt: 282, PackagesCached: 282, CacheEnabled: true,
},
want: []string{"done", "282/300 test pkgs", "282/282 built", "282 cached, 100.0%"},
},
} {
t.Run(tt.name, func(t *testing.T) {
got := tt.p.line()
for _, want := range tt.want {
if !strings.Contains(got, want) {
t.Errorf("line %q does not contain %q", got, want)
}
}
})
}
}
func TestTestETA(t *testing.T) {
oldJobs := *jobs
*jobs = 2
t.Cleanup(func() { *jobs = oldJobs })
now := time.Now()
s := &Server{
phase: phaseTesting, testEstimateReady: true,
testSchedule: []string{"p\x00running", "p\x00queued-slow", "p\x00queued-unknown", "p\x00done"},
testEstimates: map[string]testEstimate{
"p\x00running": {duration: 10 * time.Second, known: true},
"p\x00queued-slow": {duration: 8 * time.Second, known: true},
"p\x00queued-unknown": {duration: 4 * time.Second},
"p\x00done": {duration: time.Hour, known: true},
},
pkgs: map[string]*packageStatus{"p": {tests: map[string]*testStatus{
"running": {running: true, started: now.Add(-3 * time.Second)},
"queued-slow": {},
"queued-unknown": {},
"done": {done: true},
}}},
}
eta, unknown, ok := s.testETALocked(now)
if eta != 11*time.Second || unknown != 1 || !ok {
t.Fatalf("ETA = %v, unknown=%d, available=%v; want 11s, 1, true", eta, unknown, ok)
}
}