common

package
v0.35.4-crescendo-prev... Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: AGPL-3.0 Imports: 14 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

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) float64

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

func ConvertToNDecimalPlaces2

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

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

func GetCommitDate() time.Time

func GetCommitSha

func GetCommitSha() string

func GetJobRunDate

func GetJobRunDate() time.Time

func GetRunID

func GetRunID() string

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 / exceptions directories for cases when there were no failures / exceptions. From https://stackoverflow.com/a/30708914/5719544.

func PrintLevel2TestResult

func PrintLevel2TestResult(level2TestResult *Level2TestResult, message string) string

func SaveLinesToFile

func SaveLinesToFile(fileName string, list interface{})

func SaveToFile

func SaveToFile(fileName string, testSummary interface{})

SaveToFile save test run/summary to local JSON file.

Types

type Config

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

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

func ReadProperties

func ReadProperties(directory string) Config

type Level1Summary

type Level1Summary []Level1TestResult

type Level1TestResult

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"`
	RunID      string    `json:"run_id"`

	// test specific data
	Test      string   `json:"test"`
	Package   string   `json:"package"`
	Output    []string `json:"output,omitempty"`
	Elapsed   float64  `json:"elapsed"`
	Pass      int      `json:"pass"`
	Exception int      `json:"exception"`

	Action string `json:"-"`
}

Level1TestResult models result of a single test

type Level2Summary

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

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"`
	Exceptions      int       `json:"exceptions"`
	FailureRate     float64   `json:"failure_rate"`
	AverageDuration float64   `json:"average_duration"`
	Durations       []float64 `json:"durations"`
}

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

type Level3Summary

type Level3Summary struct {
	Exceptions []Level2TestResult `json:"exceptions"`

	// 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 float64   `json:"Elapsed"`
}

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

type SkippedTestEntry

type SkippedTestEntry struct {
	Test       string              `json:"test"`
	SkipReason unittest.SkipReason `json:"skip_reason,omitempty"`
	Package    string              `json:"package"`
	CommitDate time.Time           `json:"commit_date"`
	CommitSHA  string              `json:"commit_sha"`
	Category   string              `json:"category"`
}

Jump to

Keyboard shortcuts

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