forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flaky tests detector. (gravitational#20320)
Co-authored-by: Victor Sokolov <[email protected]>
- Loading branch information
1 parent
30d51b6
commit a496783
Showing
23 changed files
with
2,342 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Run difftest | ||
description: Runs difftest | ||
inputs: | ||
flags: | ||
description: difftest flags | ||
required: true | ||
|
||
target: | ||
description: make target | ||
required: true | ||
|
||
attempts: | ||
description: Number of runs | ||
required: false | ||
default: 30 | ||
|
||
bin: | ||
description: difftest binary location | ||
required: false | ||
default: ${GITHUB_WORKSPACE}/build.assets/tooling/bin/difftest | ||
|
||
path: | ||
description: difftest path | ||
required: false | ||
default: ${GITHUB_WORKSPACE} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Build | ||
shell: bash | ||
run: make ${{ inputs.bin }} | ||
|
||
- name: Show | ||
id: diffs | ||
shell: bash | ||
run: | | ||
${{ inputs.bin }} diff --path ${{ inputs.path }} --branch remotes/origin/${GITHUB_BASE_REF} ${{ inputs.flags }} | ||
echo "subject=$(${{ inputs.bin }} test --path ${{ inputs.path }} --branch remotes/origin/${GITHUB_BASE_REF} ${{ inputs.flags }} -u -d)" > $GITHUB_OUTPUT | ||
- name: Run | ||
shell: bash | ||
run: SUBJECT='${{ steps.diffs.outputs.subject }}' ADDFLAGS='-count ${{ inputs.attempts }}' make ${{ inputs.target }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
name: Flaky Tests Detector | ||
run-name: Flaky Tests Detector - ${{ github.run_id }} - @${{ github.actor }} | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**.go' | ||
|
||
env: | ||
ATTEMPTS: 30 | ||
|
||
jobs: | ||
test: | ||
name: Flaky tests detector | ||
runs-on: ubuntu-22.04-32core | ||
|
||
permissions: | ||
contents: read | ||
packages: read | ||
|
||
container: | ||
image: ghcr.io/gravitational/teleport-buildbox:teleport12 | ||
env: | ||
TELEPORT_ETCD_TEST: yes | ||
TELEPORT_ETCD_TEST_ENDPOINT: https://etcd0:2379 | ||
TELEPORT_XAUTH_TEST: yes | ||
TELEPORT_BPF_TEST: yes | ||
options: --cap-add=SYS_ADMIN --privileged | ||
|
||
services: | ||
etcd0: | ||
image: ghcr.io/gravitational/ci-etcd:3.3.9 | ||
options: >- | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
--add-host etcd0:127.0.0.1 | ||
ports: | ||
- 2379:2379 | ||
- 2380:2380 | ||
- 3379:3379 | ||
|
||
steps: | ||
- name: Checkout Teleport | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Prepare workspace | ||
uses: ./.github/actions/prepare-workspace | ||
|
||
- name: Mount debugfs | ||
run: mount -t debugfs none /sys/kernel/debug/ | ||
|
||
- name: Prepare unit tests | ||
run: make test-go-prepare | ||
|
||
- name: Run base difftest | ||
uses: ./.github/actions/difftest | ||
with: | ||
flags: -e "operator/**/*" -e "tool/tsh/**/*" -e "integration/**/*" -e "build.assets/**/*" -e "lib/auth/webauthncli/**/*" -e "lib/auth/touchid/**/*" -e "api/**/*" | ||
target: test-go-unit | ||
|
||
- name: Run libfido2 difftest | ||
uses: ./.github/actions/difftest | ||
with: | ||
flags: --include "lib/auth/webauthncli/**/*" | ||
target: test-go-libfido2 | ||
|
||
- name: Run touch-id difftest | ||
uses: ./.github/actions/difftest | ||
with: | ||
flags: --include "lib/auth/touchid/**/*" | ||
target: test-go-touch-id | ||
|
||
- name: Run tsh difftest | ||
uses: ./.github/actions/difftest | ||
with: | ||
flags: --include "tool/tsh/**/*" | ||
target: test-go-tsh | ||
|
||
- name: Run api difftest | ||
uses: ./.github/actions/difftest | ||
with: | ||
flags: --include "api/**/*" --relative "api" | ||
target: test-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
difftest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# difftest | ||
|
||
This tool finds tests which were changed since a previous git revision. | ||
|
||
## Usage | ||
|
||
To see changes: | ||
|
||
``` | ||
difftest diff --path . --branch master | ||
``` | ||
|
||
To get `go test` flags to run only newly appeared tests: | ||
|
||
``` | ||
difftest test --path . --branch master --exclude-updates | ||
``` | ||
|
||
## How it works | ||
|
||
1. Calls `git diff $(git merge-base --fork-point <branch>)` | ||
2. Filters all added/modified files ending with `_test.go`. | ||
3. Builds a map of `Test*` methods in every file. | ||
4. Calculates `SHA1` hash of each method body. | ||
5. Does the same for the counterpart files at the fork point. | ||
6. Compares the results. If a method was not there previously, it's marked as new. If a method's contents was changed, it is marked as changed. | ||
|
||
## `testify/suite` support | ||
|
||
1. Tool detects suite start signatures like the following: | ||
|
||
``` | ||
func TestSingleSuite(t *testing.T) { suite.Run(t, &SingleSuite{}) } | ||
``` | ||
where `suite` references to `testify/suite` package, and `t` references `testing` package. | ||
2. All methods related to a single suite must be in the same package (directory). | ||
3. All suite parts must redside in a files matching `*_test.go` pattern. | ||
3. If a test method has a receiver, which was not detected as a `testify/suite` previously, such method got skipped. |
Oops, something went wrong.