Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .project/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ linters-settings:
goconst:
min-len: 2
min-occurrences: 4
lll:
line-length: 120

issues:
exclude-use-default: false
Expand Down Expand Up @@ -34,7 +32,6 @@ linters:
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
Expand Down
22 changes: 15 additions & 7 deletions testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,12 @@ func (p *Package) IsEmpty() bool {

const neverFinished time.Duration = -1

// end adds any tests that were missing an ActionFail TestEvent to the list of
// strays adds any tests that were missing an ActionFail TestEvent to the list of
// Failed, and returns a slice of artificial TestEvent for the missing ones.
//
// This is done to work around 'go test' not sending the ActionFail TestEvents
// in some cases, when a test panics.
func (p *Package) end() []TestEvent {
func (p *Package) strays() []TestEvent {
result := make([]TestEvent, 0, len(p.running))
for k, tc := range p.running {
if tc.Test.IsSubTest() && rootTestPassed(p, tc) {
Expand Down Expand Up @@ -307,6 +307,10 @@ func rootTestPassed(p *Package, subtest TestCase) bool {
continue
}

// A TestCase name can exist more than once in an Execution due to
// the go test -count=n flag or when the input contains multiple separate
// test runs.
// Check the testcase has the correct ID for this subtest.
for _, subID := range p.subTests[tc.ID] {
if subID == subtest.ID {
return true
Expand Down Expand Up @@ -447,7 +451,11 @@ func (p *Package) addTestEvent(event TestEvent) {
// If this is a subtest, mark the root test as having a failed subtest
if tc.Test.IsSubTest() {
root, _ := TestName(event.Test).Split()
rootTestCase := p.running[root]
rootTestCase, ok := p.running[root]
if !ok {
rootTestCase = p.newTestCaseFromEvent(event)
rootTestCase.Test = TestName(root)
}
rootTestCase.hasSubTestFailed = true
p.running[root] = rootTestCase
}
Expand Down Expand Up @@ -639,11 +647,10 @@ func (e *Execution) HasPanic() bool {
return false
}

func (e *Execution) end() []TestEvent {
e.done = true
func (e *Execution) Strays() []TestEvent {
var result []TestEvent // nolint: prealloc
for _, pkg := range e.packages {
result = append(result, pkg.end()...)
result = append(result, pkg.strays()...)
}
return result
}
Expand Down Expand Up @@ -726,11 +733,12 @@ func ScanTestOutput(config ScanConfig) (*Execution, error) {
})

err := group.Wait()
for _, event := range execution.end() {
for _, event := range execution.Strays() {
if err := config.Handler.Event(event, execution); err != nil {
return execution, err
}
}
execution.done = true
return execution, err
}

Expand Down
32 changes: 32 additions & 0 deletions testjson/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,38 @@ func (s *captureHandler) Err(text string) error {
return nil
}

func TestScanTestOuput_SubtestWithNoRunningRoot(t *testing.T) {
source := []byte(`{"Action":"start","Package":"k8s.io/kubernetes/test/integration/scheduler_perf"}
{"Action":"skip","Package":"k8s.io/kubernetes/test/integration/scheduler_perf","Test":"BenchmarkPerfScheduling/SchedulingBasic/500Nodes"}
{"Action":"skip","Package":"k8s.io/kubernetes/test/integration/scheduler_perf","Test":"BenchmarkPerfScheduling/SchedulingPodAntiAffinity/500Nodes"}
{"Action":"skip","Package":"k8s.io/kubernetes/test/integration/scheduler_perf","Test":"BenchmarkPerfScheduling/SchedulingSecrets/500Nodes"}
{"Action":"skip","Package":"k8s.io/kubernetes/test/integration/scheduler_perf","Test":"BenchmarkPerfScheduling/SchedulingPodAffinity/500Nodes"}
{"Action":"skip","Package":"k8s.io/kubernetes/test/integration/scheduler_perf","Test":"BenchmarkPerfScheduling/SchedulingPreferredPodAntiAffinity/500Nodes"}
{"Action":"fail","Package":"k8s.io/kubernetes/test/integration/scheduler_perf","Test":"BenchmarkPerfScheduling/SchedulingDaemonset/15000Nodes"}
{"Action":"fail","Package":"k8s.io/kubernetes/test/integration/scheduler_perf","Test":"BenchmarkPerfScheduling/SchedulingDaemonset"}
{"Action":"skip","Package":"k8s.io/kubernetes/test/integration/scheduler_perf","Test":"BenchmarkPerfScheduling/SchedulingNodeAffinity/500Nodes"}
{"Action":"fail","Package":"k8s.io/kubernetes/test/integration/scheduler_perf","Elapsed":660.472}`)

handler := &captureHandler{}
cfg := ScanConfig{
Stdout: bytes.NewReader(source),
Handler: handler,
}
exec, err := ScanTestOutput(cfg)
assert.NilError(t, err)
actual := FilterFailedUnique(exec.Failed())

expected := []TestCase{
{
ID: 6,
Package: "k8s.io/kubernetes/test/integration/scheduler_perf",
Test: "BenchmarkPerfScheduling/SchedulingDaemonset/15000Nodes",
},
}
cmpTestCase := cmp.AllowUnexported(TestCase{})
assert.DeepEqual(t, expected, actual, cmpTestCase)
}

func TestFilterFailedUnique_MultipleNested(t *testing.T) {
source := []byte(`{"Package": "pkg", "Action": "run"}
{"Package": "pkg", "Test": "TestParent", "Action": "run"}
Expand Down