Commit 24ed8c2b authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

[PM] Fix move assignment operator for VoteReceipt

The move assignment operator was not properly cleaning up the current
state before taking the values from the other instance.

This CL fixes the bug and adds a test to ensures it works.

Bug: 1139433
Change-Id: I100bf33600f7441ef798a9e9d66e092ffdc1e058
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2481444
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Commit-Queue: Chris Hamilton <chrisha@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818094}
parent c3073bd1
......@@ -163,6 +163,8 @@ VoteReceipt::VoteReceipt(AcceptedVote* vote) : vote_(vote) {
}
void VoteReceipt::Take(VoteReceipt&& rhs) {
Reset();
vote_ = rhs.vote_;
// Update the back-pointer from the vote.
......
......@@ -235,5 +235,21 @@ TEST(ExecutionContextPriorityTest, VoteReceiptsWork) {
EXPECT_FALSE(consumer.votes_[0].IsValid());
}
// Tests that an overwritten vote receipt will property clean up its state.
TEST(ExecutionContextPriorityTest, OverwriteVoteReceipt) {
test::DummyVoteConsumer consumer;
VotingChannel voting_channel =
consumer.voting_channel_factory_.BuildVotingChannel();
VoteReceipt receipt = voting_channel.SubmitVote(
Vote(kDummyExecutionContext1, base::TaskPriority::HIGHEST, kReason1));
receipt = voting_channel.SubmitVote(
Vote(kDummyExecutionContext2, base::TaskPriority::HIGHEST, kReason1));
// The first vote was invalidated because its vote receipt was cleaned up.
consumer.ExpectInvalidVote(0);
}
} // namespace execution_context_priority
} // namespace performance_manager
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment