JosiahWI commented on code in PR #13283:
URL: https://github.com/apache/trafficserver/pull/13283#discussion_r3428520967


##########
src/iocore/eventsystem/unit_tests/inkevent_test_fixtures.h:
##########
@@ -0,0 +1,157 @@
+/** @file
+
+  Shared test fixtures for inkevent Catch2 unit tests.
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#pragma once
+
+#include <atomic>
+#include <chrono>
+#include <thread>
+
+#include <catch2/catch_test_macros.hpp>
+#include <catch2/reporters/catch_reporter_event_listener.hpp>
+#include <catch2/reporters/catch_reporter_registrars.hpp>
+#include <catch2/interfaces/catch_interfaces_config.hpp>
+
+#include "iocore/eventsystem/EventSystem.h"
+#include "tscore/Layout.h"
+
+#include "iocore/utils/diags.i"
+
+namespace inkevent_test
+{
+
+inline constexpr int    DEFAULT_TEST_THREADS   = 2;
+inline constexpr size_t DEFAULT_TEST_STACKSIZE = 1048576;
+inline constexpr auto   DEFAULT_TIMEOUT        = std::chrono::seconds{5};
+
+/**
+  Catch2 event listener that boots the inkevent eventProcessor once per
+  test executable. Mirrors the in-file listener used by test_EventSystem.cc
+  / test_IOBuffer.cc; lifted here so each new inkevent test file registers
+  the listener with a single CATCH_REGISTER_LISTENER call rather than
+  duplicating the boot logic.
+*/
+struct EventProcessorListener : Catch::EventListenerBase {
+  using EventListenerBase::EventListenerBase;
+
+  void
+  testRunStarting(Catch::TestRunInfo const & /* testRunInfo ATS_UNUSED */) 
override
+  {
+    Layout::create();
+    init_diags("", nullptr);
+    RecProcessInit();
+
+    ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION);
+    eventProcessor.start(DEFAULT_TEST_THREADS, DEFAULT_TEST_STACKSIZE);
+
+    EThread *main_thread = new EThread;
+    main_thread->set_specific();
+  }
+};
+
+/**
+  Atomic boolean flag with a bounded acquire-load wait. Used by
+  multi-threaded tests to observe a one-shot signal from a Continuation
+  handler without sleeping in the assertion path.
+*/
+class AtomicFlag
+{
+public:
+  void
+  set()
+  {
+    flag.store(true, std::memory_order_release);
+  }
+
+  bool
+  is_set() const
+  {
+    return flag.load(std::memory_order_acquire);
+  }
+
+  bool
+  wait_until_set(std::chrono::milliseconds timeout = 
std::chrono::duration_cast<std::chrono::milliseconds>(DEFAULT_TIMEOUT))
+  {
+    auto deadline = std::chrono::steady_clock::now() + timeout;
+    while (!flag.load(std::memory_order_acquire)) {
+      if (std::chrono::steady_clock::now() >= deadline) {
+        return false;
+      }
+      std::this_thread::yield();
+    }
+    return true;
+  }
+
+private:
+  std::atomic<bool> flag{false};
+};
+
+/**
+  Continuation whose handler counts every dispatch into a public atomic
+  counter. The first consumer is the Continuation tests in
+  test_Continuation.cc; later inkevent tests reuse it whenever they need
+  to observe handler invocations as an externally-visible side effect
+  (FR-003).

Review Comment:
   Need to remove this. 😡 



-- 
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]

Reply via email to