Skip to content

Commit a6bb989

Browse files
Ahmad Rizqi MeydiarsoAhmad Rizqi Meydiarso
authored andcommitted
fix failing maxretries test
1 parent f412c3e commit a6bb989

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

internal/scheduler/dispatcher_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,8 @@ func TestDispatcher_DispatchQueueWorker(t *testing.T) {
597597
err = redisClient.RPush(ctx, dispatchQueueKey, data).Err()
598598
require.NoError(t, err)
599599

600-
// Setup HTTP mock to always fail for every attempt
601-
mockHTTP.On("Do", mock.AnythingOfType("*http.Request")).Return((*http.Response)(nil), errors.New("fail")).Maybe()
600+
// Setup HTTP mock to always fail for every attempt (expect maxRetries+1 calls)
601+
mockHTTP.On("Do", mock.AnythingOfType("*http.Request")).Return((*http.Response)(nil), errors.New("fail")).Times(dispatcher.maxRetries + 1)
602602

603603
// Run worker and wait for completion (wait for 2 retries, less than maxRetries=3)
604604
runWorkerAndWait(ctx, dispatcher, scheduler, 400*time.Millisecond)

scripts/test.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

3-
# Exit on error
4-
set -e
3+
# Exit on error (disabled to allow all tests to run)
4+
# set -e
55

66
# Wait for PostgreSQL to be ready
77
echo "Waiting for PostgreSQL to be ready..."
@@ -50,6 +50,8 @@ PKGS=$(go list ./internal/...)
5050

5151
PASS_COUNT=0
5252
FAIL_COUNT=0
53+
ALL_TEST_OUTPUT=""
54+
FAIL_OUTPUTS=""
5355

5456
for PKG in $PKGS; do
5557
echo -e "\n=== Running tests in $PKG ==="
@@ -60,18 +62,32 @@ for PKG in $PKGS; do
6062
fi
6163
for test in $TESTS; do
6264
echo -e "\n--- Running $test in $PKG ---"
63-
if go test -v -run "^$test$" $PKG; then
65+
TEST_OUTPUT=$(go test -v -run "^$test$" $PKG)
66+
echo "$TEST_OUTPUT"
67+
ALL_TEST_OUTPUT="$ALL_TEST_OUTPUT\n$TEST_OUTPUT"
68+
if echo "$TEST_OUTPUT" | grep -q '^--- PASS'; then
6469
PASS_COUNT=$((PASS_COUNT+1))
6570
else
6671
FAIL_COUNT=$((FAIL_COUNT+1))
72+
FAIL_OUTPUTS="$FAIL_OUTPUTS\n\n===== FAILED TEST: $test in $PKG =====\n$TEST_OUTPUT"
6773
fi
6874
done
75+
76+
# Optionally, you can add a small sleep here if needed
77+
# sleep 0.1
78+
6979
done
7080

81+
# Count all '=== RUN' lines (including subtests)
82+
RUN_COUNT=$(echo "$ALL_TEST_OUTPUT" | grep '^=== RUN' | wc -l)
7183
echo -e "\nAll tests completed."
7284
echo "Passed: $PASS_COUNT"
7385
echo "Failed: $FAIL_COUNT"
86+
echo "Total RUN (including subtests): $RUN_COUNT"
87+
7488
if [ "$FAIL_COUNT" -ne 0 ]; then
89+
echo -e "\n\n==================== FAILED TEST OUTPUTS ===================="
90+
echo -e "$FAIL_OUTPUTS"
7591
exit 1
7692
fi
7793

0 commit comments

Comments
 (0)