Skip to content

Commit e677ab0

Browse files
ellemoutonguggero
authored andcommitted
make: unit test flake hunter
For convenient flake hunting.
1 parent 776fbb0 commit e677ab0

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ unit:
198198
mkdir -p app/build && touch app/build/index.html
199199
$(UNIT)
200200

201+
#? unit-debug: Run unit tests with debug log output enabled
202+
unit-debug:
203+
@$(call print, "Running unit tests.")
204+
mkdir -p app/build && touch app/build/index.html
205+
$(UNIT_DEBUG)
206+
201207
unit-cover: $(GOACC_BIN)
202208
@$(call print, "Running unit coverage tests.")
203209
$(GOACC_BIN) $(COVER_PKG)
@@ -308,6 +314,11 @@ sqlc-check: sqlc
308314
@$(call print, "Verifying sql code generation.")
309315
if test -n "$$(git status --porcelain '*.go')"; then echo "SQL models not properly generated!"; git status --porcelain '*.go'; exit 1; fi
310316

317+
#? flakehunter-unit: Run the unit tests continuously until one fails
318+
flakehunter-unit:
319+
@$(call print, "Flake hunting unit test.")
320+
scripts/unit-test-flake-hunter.sh ${pkg} ${case}
321+
311322
# Prevent make from interpreting any of the defined goals as folders or files to
312323
# include in the build process.
313324
.PHONY: default all yarn-install build install go-build go-build-noui \

make/testing_flags.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ UNIT_TARGETED ?= no
5151
# targeted case. Otherwise, default to running all tests.
5252
ifeq ($(UNIT_TARGETED), yes)
5353
UNIT := $(GOTEST) -tags="$(DEV_TAGS) $(COMPILE_TAGS)" $(TEST_FLAGS) $(UNITPKG)
54+
UNIT_DEBUG := $(GOTEST) -v -tags="$(DEV_TAGS) $(COMPILE_TAGS)" $(TEST_FLAGS) $(UNITPKG)
5455
endif
5556

5657
ifeq ($(UNIT_TARGETED), no)
5758
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) -tags="$(DEV_TAGS) $(COMPILE_TAGS)" $(TEST_FLAGS)
59+
UNIT_DEBUG := $(GOLIST) | $(XARGS) env $(GOTEST) -v -tags="$(DEV_TAGS) $(COMPILE_TAGS)" $(TEST_FLAGS)
5860
endif
5961

6062
UNIT_RACE := $(UNIT) -race

scripts/unit-test-flake-hunter.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Check if pkg and case variables are provided.
4+
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
5+
echo "Usage: $0 <pkg> <case> [timeout]"
6+
exit 1
7+
fi
8+
9+
pkg=$1
10+
case=$2
11+
timeout=${3:-30s} # Default to 30s if not provided.
12+
13+
counter=0
14+
15+
# Run the command in a loop until it fails.
16+
while output=$(go clean -testcache && make unit-debug log="stdlog trace" pkg=$pkg case=$case timeout=$timeout 2>&1); do
17+
((counter++))
18+
echo "Test $case passed, count: $counter"
19+
done
20+
21+
# Only log the output when it fails.
22+
echo "Test $case failed. Output:"
23+
echo "$output"

0 commit comments

Comments
 (0)