JosiahWI commented on code in PR #13538:
URL: https://github.com/apache/trafficserver/pull/13538#discussion_r3766510123
##########
src/records/unit_tests/test_RecRegister.cc:
##########
@@ -17,11 +17,16 @@
or implied. See the License for the specific language governing permissions
and limitations under
the License.
*/
+#include <atomic>
+#include <string>
+#include <thread>
Review Comment:
Nit: it's better to include standard headers after local project headers to
expose missing includes quickly.
##########
src/records/unit_tests/test_RecRegister.cc:
##########
@@ -87,3 +92,43 @@ TEST_CASE("RecRegisterStat - Type Dispatch",
"[librecords][RecStat]")
REQUIRE(value == 500);
}
}
+
+TEST_CASE("RecLookupRecord - Concurrent metric registration",
"[librecords][RecLookup]")
+{
+ constexpr char record_name[] = "proxy.test.concurrent.string_value";
+ constexpr char record_value[] = "stable";
+
+ REQUIRE(RecRegisterConfigString(RECT_CONFIG, record_name, record_value,
RECU_DYNAMIC, RECC_NULL, nullptr, REC_SOURCE_NULL) ==
+ REC_ERR_OKAY);
+
+ std::atomic<bool> start{false};
+ std::atomic<bool> finished{false};
+ std::thread register_metrics([&]() {
+ while (!start.load(std::memory_order_acquire)) {
+ std::this_thread::yield();
+ }
+
+ for (int i = 0; i < 100000; ++i) {
+ auto metric_name =
std::string{"proxy.process.test.concurrent_metric_registration."} +
std::to_string(i);
+
+ ts::Metrics::Counter::create(metric_name);
+ }
+ finished.store(true, std::memory_order_release);
+ });
+
+ bool all_lookups_succeeded = true;
+ size_t lookup_count = 0;
+
+ start.store(true, std::memory_order_release);
+ while (!finished.load(std::memory_order_acquire)) {
+ if (RecGetRecordStringAlloc(record_name) != record_value) {
+ all_lookups_succeeded = false;
+ break;
+ }
+ ++lookup_count;
+ }
Review Comment:
This loop can run 0 times in theory, which will fail the test. What was the
intent here?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]