JosiahWI commented on code in PR #13818: URL: https://github.com/apache/trafficserver/pull/13818#discussion_r4225714259
########## src/iocore/cache/unit_tests/test_Read_Close_During_IO.cc: ########## @@ -0,0 +1,206 @@ +/** @file + + Closing a cache read while the read of the next fragment is in flight. + + @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. + */ + +#include "main.h" + +#include <cstddef> +#include <memory> + +int cache_vols = 1; +bool reuse_existing_cache = false; + +namespace +{ + +constexpr std::size_t LARGE_FILE = 10 * 1024 * 1024; +constexpr char OBJECT_URL[] = "http://www.close-during-read.com/"; + +class WriteObject : public CacheTestHandler +{ +public: + WriteObject(std::size_t size, const char *url) : CacheTestHandler() + { + this->_wt = new CacheWriteTest(size, this, url); + this->_wt->mutex = this->mutex; + + SET_HANDLER(&WriteObject::start_test); + } + + int + start_test(int /* event ATS_UNUSED */, void * /* e ATS_UNUSED */) + { + this_ethread()->schedule_imm(this->_wt); + return 0; + } + + void + handle_cache_event(int event, CacheTestBase *base) override + { + switch (event) { + case CACHE_EVENT_OPEN_WRITE: + base->do_io_write(); + break; + case VC_EVENT_WRITE_READY: + base->reenable(); + break; + case VC_EVENT_WRITE_COMPLETE: + base->close(); + delete this; + break; + default: + FAIL("unexpected event " << event << " while writing the object"); + break; + } + } +}; + +class CloseReadDuringIO : public CacheTestHandler +{ +public: + CloseReadDuringIO(std::size_t size, const char *url) : CacheTestHandler(), _size(size), _url(url) + { + this->_rt = new CacheReadTest(size, this, url); + this->_rt->mutex = this->mutex; + + SET_HANDLER(&CloseReadDuringIO::start_test); + } + + ~CloseReadDuringIO() override { delete this->_closed_reader; } + + int + start_test(int /* event ATS_UNUSED */, void * /* e ATS_UNUSED */) + { + this_ethread()->schedule_imm(this->_rt); + return 0; + } + + // The cache starts reading the next fragment after the READ_READY callback + // returns, so closing from a separate event closes during that read. + int + close_reader(int /* event ATS_UNUSED */, void * /* e ATS_UNUSED */) + { + this->_rt->vc->do_io_close(); Review Comment: After further consideration, I am personally convinced that the disk read is an implementation detail and should not be asserted in a unit test. However, the test claims to be testing more than it should, which is the root cause of CoPilot's change request. Patch coming soon. -- 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]
