ashb commented on code in PR #43893: URL: https://github.com/apache/airflow/pull/43893#discussion_r1840762991
########## task_sdk/tests/execution_time/test_task_runner.py: ########## @@ -0,0 +1,57 @@ +# 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. + +from __future__ import annotations + +import uuid +from socket import socketpair + +import pytest + +from airflow.sdk.execution_time.comms import StartupDetails +from airflow.sdk.execution_time.task_runner import CommsDecoder + + +class TestCommsDecoder: + """Test the communication between the subprocess and the "supervisor".""" + + @pytest.mark.usefixtures("disable_capturing") + def test_recv_StartupDetails(self): + r, w = socketpair() + # Create a valid FD for the decoder to open + _, w2 = socketpair() + + w.makefile("wb").write( + b'{"type":"StartupDetails", "ti": {' + b'"id": "4d828a62-a417-4936-a7a6-2b3fabacecab", "task_id": "a", "try_number": 1, "run_id": "b", "dag_id": "c" }, ' + b'"file": "/dev/null", "requests_fd": ' + str(w2.fileno()).encode("ascii") + b"}\n" + ) + + decoder = CommsDecoder(input=r.makefile("r")) + + msg = decoder.get_message() + assert isinstance(msg, StartupDetails) + assert msg.ti.id == uuid.UUID("4d828a62-a417-4936-a7a6-2b3fabacecab") + assert msg.ti.task_id == "a" + assert msg.ti.dag_id == "c" + assert msg.file == "/dev/null" + + # Since this was a StartupDetails message, the decoder should open the other socket + assert decoder.request_socket.writable() + assert decoder.request_socket.fileno() == w2.fileno() + + ... Review Comment: Whops, left over. -- 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]
