这是indexloc提供的服务,不要输入任何密码
Skip to content

fix(pubsub/pstest): message ordering issue #11603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 17, 2025

Conversation

larryanz
Copy link
Contributor

@larryanz larryanz commented Feb 18, 2025

As explained in #11592, currently the pstest's message ordering can not be ensured because of the accuracy of using comparison by *timestamppb.Timestamp instead of standard time.Time.

The solution is changing the comparison logic from proto time back to message published time.

How to test/ re-produce the error:

Since this error happens quite randomly, we can use this script to do a fuzz test. The script will fail on main branch and succeed on this fix branch.

#!/bin/bash

# Default values for flags
print_output=false
count_tests=true
iterations=100

# Parse command-line flags
while getopts "pc:i:" opt; do
  case $opt in
    p) print_output=true ;;  # Enable printing output
    c) count_tests=true ;;   # Enable counting
    i) iterations=$OPTARG ;; # Set the number of iterations (default 1000)
    \?) echo "Usage: $0 [-p] [-c] [-i iterations]"
        exit 1 ;;
  esac
done

# Variables to count passes and fails
pass_count=0
fail_count=0

# Loop through test runs
for (( i=1; i<=iterations; i++ )); do
    output=$(go test -timeout 2s -run ^TestSubscriptionMessageOrdering$ cloud.google.com/go/pubsub/pstest -count=1)

    # Print the output if the flag is set
    if $print_output; then
        echo "$output"
    fi

    # Count pass/fail if the flag is set
    if $count_tests; then
        if echo "$output" | grep -q "ok\s*cloud.google.com/go/pubsub/pstest"; then
            ((pass_count++))
        elif echo "$output" | grep -q "FAIL\s*cloud.google.com/go/pubsub/pstest"; then
            ((fail_count++))
        fi
    fi

    # Print progress after each iteration
    if $count_tests; then
        echo "Iteration $i/$iterations - Passed: $pass_count, Failed: $fail_count"
    fi
done

# Print final count results if the flag is set
if $count_tests; then
    echo "Final Results: Passed tests: $pass_count, Failed tests: $fail_count"
fi

@larryanz larryanz requested review from shollyman and a team as code owners February 18, 2025 08:18
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Feb 18, 2025
@larryanz
Copy link
Contributor Author

hi @hongalex, please help to review this PR

@@ -0,0 +1,50 @@
#!/bin/bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not include this file in the fix. Create a gist instead and add it to the PR description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @hongalex , I updated

@larryanz larryanz force-pushed the fix/fix-message-ordering-pstest branch from 037551a to 9bc5764 Compare March 13, 2025 04:42
@hongalex hongalex added the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 17, 2025
@hongalex hongalex enabled auto-merge (squash) March 17, 2025 19:59
@kokoro-team kokoro-team removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Mar 17, 2025
@hongalex hongalex merged commit 1d6ffc0 into googleapis:main Mar 17, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants