[ledger][benchmarks] Don't shut down benchmark until all put operations have terminated.
Test: put benchmarks
It is possible that the watcher notifications are received before the
callback of Put is called. E.g. this happened during CL /244232. After
this CL we are waiting on both watcher notifications and put callbacks
to terminate before shuting down.
Change-Id: I7866d31de4c95c5e4c2acb0511a3356f5e96845b
diff --git a/bin/ledger/tests/benchmark/put/put.cc b/bin/ledger/tests/benchmark/put/put.cc
index 55847d1..a9b1fd5 100644
--- a/bin/ledger/tests/benchmark/put/put.cc
+++ b/bin/ledger/tests/benchmark/put/put.cc
@@ -99,6 +99,12 @@
// contains all the keys, otherwise only the last changed key for each
// transaction.
std::set<size_t> keys_to_receive_;
+ // Whether all Put operations have terminated. Shut down should be blocked
+ // until this is set to true.
+ bool insertions_finished_ = false;
+ // Whether all expected watch notifications have been received. Shut down
+ // should be blocked until this is set to true.
+ bool all_watcher_notifications_received_ = false;
FXL_DISALLOW_COPY_AND_ASSIGN(PutBenchmark);
};
@@ -191,7 +197,12 @@
}
}
if (keys_to_receive_.empty()) {
- ShutDown();
+ all_watcher_notifications_received_ = true;
+ // All watcher notifications have been received, waiting for put operations
+ // to finish before shutting down.
+ if (insertions_finished_) {
+ ShutDown();
+ }
}
callback(nullptr);
}
@@ -243,7 +254,11 @@
void PutBenchmark::RunSingle(int i, std::vector<std::vector<uint8_t>> keys) {
if (i == entry_count_) {
- // All sent, waiting for watcher notification before shutting down.
+ insertions_finished_ = true;
+ // All sent, waiting for watcher notifications before shutting down.
+ if (all_watcher_notifications_received_) {
+ ShutDown();
+ }
return;
}