Skip to content
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

Fix race in test "CLUSTER SLOT-STATS cpu-usec for blocking commands, unblocked on timeout" #1416

Merged

Conversation

zuiderkwast
Copy link
Contributor

This fix changes the timeout for BLPOP in this test case from 1 second to 0.5 seconds.

In the test case quoted below, the procedure wait_for_blocked_clients_count waits for one second by default. If BLPOP has 1 second timeout and the first wait_for_blocked_clients_count finishes very fast, then the second wait_for_blocked_clients_count can time out before the BLPOP has been unblocked.

    test "CLUSTER SLOT-STATS cpu-usec for blocking commands, unblocked on timeout." {
        # Blocking command with 1 second timeout.
        set rd [valkey_deferring_client]
        $rd BLPOP $key 1

        # Confirm that the client is blocked, then unblocked after 1 second timeout.
        wait_for_blocked_clients_count 1
        wait_for_blocked_clients_count 0

As seen in the definition of wait_for_blocked_clients_count, the total time to wait is 1 second by default.

proc wait_for_blocked_clients_count {count {maxtries 100} {delay 10} {idx 0}} {
    wait_for_condition $maxtries $delay  {
        [s $idx blocked_clients] == $count
    } else {
        fail "Timeout waiting for blocked clients"
    }
}

Fixes #1121

…nds, unblocked on timeout"

The command BLPOP blocks for 1 second.

The procedure `wait_for_blocked_clients_count` waits for one second by default.
If the first `wait_for_blocked_clients_count` finishes very fast, then the second
`wait_for_blocked_clients_count` can time out before the BLPOP has been unblocked.

```TCL
    test "CLUSTER SLOT-STATS cpu-usec for blocking commands, unblocked on timeout." {
        # Blocking command with 1 second timeout.
        set rd [valkey_deferring_client]
        $rd BLPOP $key 1

        # Confirm that the client is blocked, then unblocked after 1 second timeout.
        wait_for_blocked_clients_count 1
        wait_for_blocked_clients_count 0
```

As seen in the definition of `wait_for_blocked_clients_count`, the total time to
wait is 1 second by default.

```TCL
proc wait_for_blocked_clients_count {count {maxtries 100} {delay 10} {idx 0}} {
    wait_for_condition $maxtries $delay  {
        [s $idx blocked_clients] == $count
    } else {
        fail "Timeout waiting for blocked clients"
    }
}
```

Signed-off-by: Viktor Söderqvist <[email protected]>
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.86%. Comparing base (f951a1c) to head (3672303).
Report is 2 commits behind head on unstable.

Additional details and impacted files
@@            Coverage Diff            @@
##           unstable    #1416   +/-   ##
=========================================
  Coverage     70.85%   70.86%           
=========================================
  Files           118      118           
  Lines         63612    63612           
=========================================
+ Hits          45075    45079    +4     
+ Misses        18537    18533    -4     

see 12 files with indirect coverage changes

@zuiderkwast zuiderkwast merged commit 2dfe25b into valkey-io:unstable Dec 10, 2024
47 checks passed
@zuiderkwast zuiderkwast deleted the fix-race-in-slot-stats-test branch December 10, 2024 13:46
@zuiderkwast zuiderkwast added the test-failure An issue indicating a test failure label Dec 10, 2024
vudiep411 pushed a commit to Autxmaton/valkey that referenced this pull request Dec 15, 2024
…unblocked on timeout" (valkey-io#1416)

This fix changes the timeout for BLPOP in this test case from 1 second
to 0.5 seconds.

In the test case quoted below, the procedure
`wait_for_blocked_clients_count` waits for one second by default. If
BLPOP has 1 second timeout and the first
`wait_for_blocked_clients_count` finishes very fast, then the second
`wait_for_blocked_clients_count` can time out before the BLPOP has been
unblocked.

```TCL
    test "CLUSTER SLOT-STATS cpu-usec for blocking commands, unblocked on timeout." {
        # Blocking command with 1 second timeout.
        set rd [valkey_deferring_client]
        $rd BLPOP $key 1

        # Confirm that the client is blocked, then unblocked after 1 second timeout.
        wait_for_blocked_clients_count 1
        wait_for_blocked_clients_count 0
```

As seen in the definition of `wait_for_blocked_clients_count`, the total
time to wait is 1 second by default.

```TCL
proc wait_for_blocked_clients_count {count {maxtries 100} {delay 10} {idx 0}} {
    wait_for_condition $maxtries $delay  {
        [s $idx blocked_clients] == $count
    } else {
        fail "Timeout waiting for blocked clients"
    }
}
```

Fixes valkey-io#1121

Signed-off-by: Viktor Söderqvist <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test-failure An issue indicating a test failure
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[test-failure] CLUSTER SLOT-STATS cpu-usec for blocking commands, unblocked on timeout
2 participants