common

package
v0.25.14-cadence-v0.23... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package common has helper / utility functions used by all levels of flaky test monitor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertLevel2TestResults added in v0.25.2

func AssertLevel2TestResults(t *testing.T, expectedLevel2TestResult, actualLevel2TestResult Level2TestResult)

AssertLevel2TestResults checks that 2 Level2TestResult structs are equal, doing a deep comparison. This is needed for multiple test files (level 2 and 3) so it's extracted as a helper function here.

func AssertNoError

func AssertNoError(err error, panicMessage string)

AssertNoError checks that the passed in error is nil and panics with the supplied message if that's not the case. Useful helper to eliminate the need to keep checking for errors.

func ConvertToNDecimalPlaces

func ConvertToNDecimalPlaces(n int, numerator, denominator int) float32

ConvertToNDecimalPlaces converts the supplied numerator and denominator fraction into a decimal with n decimal places.

func ConvertToNDecimalPlaces2

func ConvertToNDecimalPlaces2(n int, numerator float32, denominator int) float32

ConvertToNDecimalPlaces2 converts the supplied numerator and denominator fraction into a decimal with n decimal places. Works the same way as ConvertToNDecimalPlaces() but has a float for the numerator.

func DirExists

func DirExists(path string) bool

DirExists checks if directory exists and return true if it does, false otherwise.

func GetCommitDate added in v0.25.2

func GetCommitDate() time.Time

func GetCommitSha added in v0.25.2

func GetCommitSha() string

func GetJobRunDate added in v0.25.2

func GetJobRunDate() time.Time

func IsDirEmpty

func IsDirEmpty(name string) bool

IsDirEmpty checks if directory is empty (has no files) and return true if it's empty, false otherwise. Useful for determining whether to delete the failures / no-results directories for cases when there were no failures / no-results. From https://stackoverflow.com/a/30708914/5719544.

func PrintLevel2TestResult added in v0.25.2

func PrintLevel2TestResult(level2TestResult *Level2TestResult, message string) string

func SaveToFile

func SaveToFile(fileName string, testSummary interface{})

SaveToFile save test run/summary to local JSON file.

Types

type Config

type Config struct {
	FailureThresholdPercent float32 `json:"failures_threshold_percent"`
	FailuresSliceMax        int     `json:"failures_slice_max"`

	DurationThresholdSeconds float32 `json:"duration_threshold_seconds"`
	DurationSliceMax         int     `json:"duration_slice_max"`
}

func ReadProperties

func ReadProperties(directory string) Config

type Level1Summary added in v0.25.2

type Level1Summary struct {
	TestMap map[string][]Level1TestResult `json:"-"`
	Rows    []Level1TestResultRow         `json:"rows"`
}

Level1Summary models full level 1 summary of a test run from "go test -json".

type Level1TestResult added in v0.25.2

type Level1TestResult struct {
	// data that spans multiple tests - it's added at the test level because it will be used
	// by BigQuery tables and will need to be flattened
	CommitSha  string    `json:"commit_sha"`
	CommitDate time.Time `json:"commit_date"`
	JobRunDate time.Time `json:"job_run_date"`

	// test specific data
	Test    string `json:"test"`
	Package string `json:"package"`
	Output  []struct {
		Item string `json:"item"`
	} `json:"output"`
	Result   string  `json:"result"`
	Elapsed  float32 `json:"elapsed"`
	NoResult bool    `json:"no_result"`
}

Level1TestResult models result of a single test

type Level1TestResultRow added in v0.25.2

type Level1TestResultRow struct {
	TestResult Level1TestResult `json:"json"`
}

type Level2Summary added in v0.25.2

type Level2Summary struct {
	TestResultsMap map[string]*Level2TestResult `json:"tests"`
}

Level2Summary models full level 2 summary of multiple tests from 1 or more level 1 test runs

type Level2TestResult added in v0.25.2

type Level2TestResult struct {
	Test            string    `json:"test"`
	Package         string    `json:"package"`
	Runs            int       `json:"runs"`
	Passed          int       `json:"passed"`
	Failed          int       `json:"failed"`
	Skipped         int       `json:"skipped"`
	NoResult        int       `json:"no_result"`
	FailureRate     float32   `json:"failure_rate"`
	AverageDuration float32   `json:"average_duration"`
	Durations       []float32 `json:"durations"`
}

Level2TestResult models all results from a specific test over many (level 1) test runs

type Level3Summary added in v0.25.2

type Level3Summary struct {
	NoResults []Level2TestResult `json:"no_results"`

	// ordered list of tests (from level 2 summary) that:
	// a) met minimum failure threshold as specified in property file property `failures_threshold_percent`
	// b) is up to maximum slice size as specified in `failures_slice_max` in property file
	MostFailures []Level2TestResult `json:"most_failures"`

	// total # of tests (from level 2 summary) that:
	// a) met minimum failure threshold as specified in property file property `failures_threshold_percent`
	MostFailuresTotal int `json:"most_failures_total"`

	// ordered list of tests (from level 2 summary) that:
	// a) met minimum duration threshold as specified in property file property `duration_threshold_seconds`
	// b) is up to maximum slice size as specified in `duration_slice_max` in property file
	LongestRunning []Level2TestResult `json:"longest_running"`

	// total # of tests (from level 2 summary) that:
	// a) met minimum duration threshold as specified in property file property `duration_threshold_seconds`
	LongestRunningTotal int `json:"longest_running_total"`
}

models full level 3 summary of a test run from 1 (single) level 2 test run

type RawTestStep

type RawTestStep struct {
	Time    time.Time `json:"Time"`
	Action  string    `json:"Action"`
	Package string    `json:"Package"`
	Test    string    `json:"Test"`
	Output  string    `json:"Output"`
	Elapsed float32   `json:"Elapsed"`
}

RawTestStep models single line from "go test -json" output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL