Skip to content

Commit

Permalink
renamed collectteststatus to collectstats
Browse files Browse the repository at this point in the history
  • Loading branch information
palashmarantas committed Mar 4, 2022
1 parent b6ba59f commit 17a6c07
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type YMLParserService interface {

// TestStats is used for servicing stat collection
type TestStats interface {
CaptureTestStats(pid int32, CollectTestStats bool) error
CaptureTestStats(pid int32, CollectStats bool) error
}

// Task is a service to update task status at neuron
Expand Down
27 changes: 13 additions & 14 deletions pkg/core/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,7 @@ func (pl *Pipeline) Start(ctx context.Context) (err error) {
return err
}

taskPayload.Status = Passed
for _, result := range executionResults.Results {
for i := 0; i < len(result.TestPayload); i++ {
testResult := &result.TestPayload[i]
if testResult.Status == "failed" {
taskPayload.Status = Failed
break
}
}
if taskPayload.Status == "failed" {
taskPayload.Status = Failed
break
}
}
taskPayload.Status = findTaskPayloadStatus(executionResults)

if tasConfig.Postrun != nil {
pl.Logger.Infof("Running post-run steps")
Expand All @@ -333,6 +320,18 @@ func (pl *Pipeline) Start(ctx context.Context) (err error) {
return nil
}

func findTaskPayloadStatus(executionResults *ExecutionResults) Status {
for _, result := range executionResults.Results {
for i := 0; i < len(result.TestPayload); i++ {
testResult := &result.TestPayload[i]
if testResult.Status == "failed" {
return Failed
}
}
}
return Passed
}

func (pl *Pipeline) sendStats(payload ExecutionResults) error {
reqBody, err := json.Marshal(payload)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type Payload struct {
ParentCommitCoverageExists bool `json:"parent_commit_coverage_exists"`
LicenseTier Tier `json:"license_tier"`
CollectCoverage bool `json:"collect_coverage"`
CollectTestStats bool `json:"collect_test_stats"`
CollectStats bool `json:"collect_stats"`
}

// Pipeline defines all attributes of Pipeline
Expand Down
8 changes: 4 additions & 4 deletions pkg/service/teststats/teststats.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func New(cfg *config.NucleusConfig, logger lumber.Logger) (*ProcStats, error) {
}

// CaptureTestStats combines the ps stats for each test
func (s *ProcStats) CaptureTestStats(pid int32, CollectTestStats bool) error {
func (s *ProcStats) CaptureTestStats(pid int32, CollectStats bool) error {
ps, err := procfs.New(pid, global.SamplingTime, false)
if err != nil {
s.logger.Errorf("failed to find process stats with pid %d %v", pid, err)
Expand All @@ -52,10 +52,10 @@ func (s *ProcStats) CaptureTestStats(pid int32, CollectTestStats bool) error {
}
select {
case executionResults := <-s.ExecutionResultInputChannel:
// Refactor the impl of below 2 functions using generics when Go 1.18 arrives
// https://www.freecodecamp.org/news/generics-in-golang/
if CollectTestStats {
if CollectStats {
for ind := range executionResults.Results {
// Refactor the impl of below 2 functions using generics when Go 1.18 arrives
// https://www.freecodecamp.org/news/generics-in-golang/
s.appendStatsToTests(executionResults.Results[ind].TestPayload, processStats)
s.appendStatsToTestSuites(executionResults.Results[ind].TestSuitePayload, processStats)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/testexecutionservice/testexecution.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (tes *testExecutionService) Run(ctx context.Context,
pid := int32(cmd.Process.Pid)
tes.logger.Debugf("execution command started with pid %d", pid)

if err := tes.ts.CaptureTestStats(pid, payload.CollectTestStats); err != nil {
if err := tes.ts.CaptureTestStats(pid, payload.CollectStats); err != nil {
tes.logger.Errorf("failed to find process for command %s with pid %d %v", cmd.String(), pid, err)
return nil, err
}
Expand Down

0 comments on commit 17a6c07

Please sign in to comment.