Skip to content

Commit

Permalink
Clear out running tests from each pkg
Browse files Browse the repository at this point in the history
Otherwise, when an Execution is re-used, those tests still in running will have artifitial
events sent for them each time .end() is called, inflating the failure count. The test
count was correct because test count is incremented in run().
  • Loading branch information
dnephin committed Jul 18, 2020
1 parent 6c2d74f commit a4b69e7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
9 changes: 0 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,6 @@ func (o options) Validate() error {
return nil
}

func (o options) rerunFailsFilter() testCaseFilter {
if o.rerunFailsOnlyRootCases {
return func(tcs []testjson.TestCase) []testjson.TestCase {
return tcs
}
}
return testjson.FilterFailedUnique
}

func setupLogging(opts *options) {
if opts.debug {
log.SetLevel(log.DebugLevel)
Expand Down
11 changes: 10 additions & 1 deletion rerunfails.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ func newRerunOptsFromTestCase(tc testjson.TestCase) rerunOpts {

type testCaseFilter func([]testjson.TestCase) []testjson.TestCase

func rerunFailsFilter(o *options) testCaseFilter {
if o.rerunFailsOnlyRootCases {
return func(tcs []testjson.TestCase) []testjson.TestCase {
return tcs
}
}
return testjson.FilterFailedUnique
}

func rerunFailed(ctx context.Context, opts *options, scanConfig testjson.ScanConfig) error {
tcFilter := opts.rerunFailsFilter()
tcFilter := rerunFailsFilter(opts)
failed := len(tcFilter(scanConfig.Execution.Failed()))
if failed > opts.rerunFailsMaxInitialFailures {
return fmt.Errorf(
Expand Down
3 changes: 2 additions & 1 deletion testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const neverFinished time.Duration = -1
// in some cases, when a test panics.
func (p *Package) end() []TestEvent {
result := make([]TestEvent, 0, len(p.running))
for _, tc := range p.running {
for k, tc := range p.running {
tc.Elapsed = neverFinished
p.Failed = append(p.Failed, tc)

Expand All @@ -219,6 +219,7 @@ func (p *Package) end() []TestEvent {
Test: tc.Test,
Elapsed: float64(neverFinished),
})
delete(p.running, k)
}
return result
}
Expand Down
4 changes: 4 additions & 0 deletions testjson/summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ func TestPrintSummary_MissingTestFailEvent(t *testing.T) {
buf := new(bytes.Buffer)
PrintSummary(buf, exec, SummarizeAll)
golden.Assert(t, buf.String(), "summary-missing-test-fail-event")

for name, pkg := range exec.packages {
assert.Equal(t, len(pkg.running), 0, "package %v still had tests in running", name)
}
}

func TestPrintSummary_WithMisattributedOutput(t *testing.T) {
Expand Down

0 comments on commit a4b69e7

Please sign in to comment.