ywkaras commented on a change in pull request #6832: URL: https://github.com/apache/trafficserver/pull/6832#discussion_r484984271
########## File path: tests/gold_tests/pluginTest/tsapi2/alt_info.h ########## @@ -0,0 +1,155 @@ +/* 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. + */ + +// Unit Test for API: TSHttpTxnCachedReqGet +// TSHttpTxnCachedRespGet +// TSHttpAltInfoClientReqGet +// TSHttpAltInfoCachedReqGet +// TSHttpAltInfoCachedRespGet +// TSHttpAltInfoQualitySet +// +namespace AltInfoTest +{ +Logger log; + +TSCont cont{nullptr}; + +struct ContData { + bool good{true}; + void + test(bool result) + { + good = good && result; + } +}; + +int +contFunc(TSCont contp, TSEvent event, void *event_data) +{ + TSReleaseAssert(event_data != nullptr); + + if (TS_EVENT_HTTP_SELECT_ALT == event) { + auto info = static_cast<TSHttpAltInfo>(event_data); + + TSMBuffer client_req_bufp; + TSMLoc client_req_mloc; + + if (TSHttpAltInfoClientReqGet(info, &client_req_bufp, &client_req_mloc) != TS_SUCCESS) { + log("Unable to get handle to client request"); + + } else { + static char const Req_id_fld_name[] = "X-Request-ID"; + + TSMLoc fld_loc = TSMimeHdrFieldFind(client_req_bufp, client_req_mloc, Req_id_fld_name, sizeof(Req_id_fld_name) - 1); + if (TS_NULL_MLOC == fld_loc) { + log("Unable to find %s field in client request", Req_id_fld_name); + + } else { + if (TSMimeHdrFieldValuesCount(client_req_bufp, client_req_mloc, fld_loc) != 1) { + log("Multiple values for %s field in client request", Req_id_fld_name); + } else { + int x_req_num = TSMimeHdrFieldValueIntGet(client_req_bufp, client_req_mloc, fld_loc, 0); + + if ((7 == x_req_num) || (8 == x_req_num)) { + log("request id number = %d", x_req_num); + + auto data = static_cast<ContData *>(TSContDataGet(contp)); + data->test(checkHttpTxnReqOrResp(log, info, TSHttpAltInfoCachedReqGet, "alt info cached request", 6)); + data->test( + checkHttpTxnReqOrResp(log, info, TSHttpAltInfoCachedRespGet, "alt info cached response", 6, TS_HTTP_STATUS_OK)); + + if (7 == x_req_num) { + // This function does not actually seem to do anything. + TSHttpAltInfoQualitySet(info, 0.5); Review comment: This function also seems to have no effect in the regression tests that this test code is based on: ``` Breakpoint 1, synclient_txn_read_response (contp=<optimized out>) at traffic_server/InkAPITest.cc:669 669 TSDebug(CDBG_TAG, "Response = |%s|, req len = %d", txn->response, txn->response_len); (gdb) p txn->response $3 = "HTTP/1.0 200 OK\r\nX-Response-ID: 6\r\nCache-Control: max-age=86400\r\nContent-Language: English\r\nDate: Tue, 08 Sep 2020 14:41:34 GMT\r\nAge: 0\r\nServer: ATS/10.0.0\r\n\r\nBody for response 6", '\000' <repeats 3917 times> (gdb) c Continuing. Regression test(SDK_API_HttpAltInfo) still in progress Breakpoint 1, synclient_txn_read_response (contp=<optimized out>) at traffic_server/InkAPITest.cc:669 669 TSDebug(CDBG_TAG, "Response = |%s|, req len = %d", txn->response, txn->response_len); (gdb) p txn->response $4 = "HTTP/1.0 200 OK\r\nX-Response-ID: 6\r\nCache-Control: max-age=86400\r\nContent-Language: English\r\nDate: Tue, 08 Sep 2020 14:41:34 GMT\r\nAge: 0\r\nContent-Length: 19\r\nServer: ATS/10.0.0\r\n\r\nBody for response 6", '\000' <repeats 3897 times> (gdb) c Continuing. [SDK_API_HttpAltInfo] TSHttpAltInfoClientReqGet : [TestCase] <<PASS>> { ok } [SDK_API_HttpAltInfo] TSHttpAltInfoCachedReqGet : [TestCase] <<PASS>> { ok } [SDK_API_HttpAltInfo] TSHttpAltInfoCachedRespGet : [TestCase] <<PASS>> { ok } [SDK_API_HttpAltInfo] TSHttpAltInfoQualitySet : [TestCase] <<PASS>> { ok } Breakpoint 1, synclient_txn_read_response (contp=<optimized out>) at traffic_server/InkAPITest.cc:669 669 TSDebug(CDBG_TAG, "Response = |%s|, req len = %d", txn->response, txn->response_len); (gdb) p txn->response $5 = "HTTP/1.0 200 OK\r\nX-Response-ID: 6\r\nCache-Control: max-age=86400\r\nContent-Language: English\r\nDate: Tue, 08 Sep 2020 14:41:34 GMT\r\nAge: 60\r\nContent-Length: 19\r\nServer: ATS/10.0.0\r\n\r\nBody for response 6", '\000' <repeats 3896 times> ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
