Fix review counters when deleting or switching close states.

Review Request #5997 — Created June 15, 2014 and submitted

Information

Review Board
release-2.0.x
a8a7644...

Reviewers

There were some obscure cases where users could trigger negative
counters in the dashboard for review requests. These have been hard to
track down, but with enough bugs opened, we had a somewhat decent
starting point for some of these.

What all the repro cases had in common was that a review request was, at
some point, discarded. In most other cases, a review request was also
permanently deleted.

Through some digging, I found there were a couple cases where you could
trigger these negative counters:

1) Closing a review request twice with two different statuses (through
the API or by opening a review request in two tabs and closing as
Submitted in one, Discarded in another).

2) Permanently deleting a closed (discarded or submitted) review
request.

What these had in common is that they were decrementing counts when not
coming from a PENDING_REVIEW state.

This change tightens the code to only decrement when we were in this
state. It also cleans up a lot of the code by moving all the
incrementing and decrementing logic into reusable functions, so that we
never become inconsistent between them.

Unit tests were added to check these new states. Additional tests were
added for other conditions I could think of (which passed anyway, but it
doesn't hurt to beef up the test suite).

I also was able to simplify and strengthen these tests by moving all the
count assertions into a utility function that would guarantee all
possible values were checked. This helped to improve readability,
maintainability, and consistency between the tests.

This change will be backported to release-1.7.x.

The new unit tests failed with -1 values without the fixes to the counter
updates. After the fixes, all tests passed.

I also verified the failures by hand, and verified they've been fixed.

reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        reviewboard/reviews/tests.py
        reviewboard/reviews/models/review_request.py
      Ignored Files:
    
    
  2. 
      
reviewbot
  1. This is a review from Review Bot.
      Tool: Pyflakes
      Processed Files:
        reviewboard/reviews/tests.py
        reviewboard/reviews/models/review_request.py
      Ignored Files:
    
    
  2. 
      
david
  1. Ship It!

  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-2.0.x (99b2e1a)