|
| 1 | +import PrecompileTools: @compile_workload |
| 2 | + |
| 3 | +# This key is used by the tests and precompilation workload to keep some |
| 4 | +# consistency in the message signatures. |
| 5 | +const _TEST_KEY = "a0436f6c-1916-498b-8eb9-e81ab9368e84" |
| 6 | + |
| 7 | +# How to update the precompilation workload: |
| 8 | +# 1. Uncomment the `@show` expressions in `recv_ipython()` in msg.jl. |
| 9 | +# 2. Copy this workload into tests/kernel.jl and update as desired: |
| 10 | +# |
| 11 | +# Kernel(profile; capture_stdout=false, capture_stderr=false) do kernel |
| 12 | +# jupyter_client(profile) do client |
| 13 | +# kernel_info(client) |
| 14 | +# execute(client, "42") |
| 15 | +# execute(client, "error(42)") |
| 16 | +# end |
| 17 | +# end |
| 18 | +# |
| 19 | +# 3. When the above runs it will print out the contents of the received messages |
| 20 | +# as strings. You can copy these verbatim into the precompilation workload |
| 21 | +# below. Note that if you modify any step of the workload you will need to |
| 22 | +# update *all* the messages to ensure they have the right parent |
| 23 | +# headers/signatures. |
| 24 | +@compile_workload begin |
| 25 | + profile = create_profile(45_000; key=_TEST_KEY) |
| 26 | + |
| 27 | + Kernel(profile; capture_stdout=false, capture_stderr=false, capture_stdin=false) do kernel |
| 28 | + # Connect as a client to the kernel |
| 29 | + requests_socket = ZMQ.Socket(ZMQ.DEALER) |
| 30 | + ip = profile["ip"] |
| 31 | + port = profile["shell_port"] |
| 32 | + ZMQ.connect(requests_socket, "tcp://$(ip):$(port)") |
| 33 | + |
| 34 | + # kernel_info |
| 35 | + idents = ["d2bd8e47-b2c9cd130d2967a19f52c1a3"] |
| 36 | + signature = "3c4f523a0e8b80e5b3e35756d75f62d12b851e1fd67c609a9119872e911f83d2" |
| 37 | + header = "{\"msg_id\": \"d2bd8e47-b2c9cd130d2967a19f52c1a3_3534705_0\", \"msg_type\": \"kernel_info_request\", \"username\": \"james\", \"session\": \"d2bd8e47-b2c9cd130d2967a19f52c1a3\", \"date\": \"2025-02-20T22:29:47.616834Z\", \"version\": \"5.4\"}" |
| 38 | + parent_header = "{}" |
| 39 | + metadata = "{}" |
| 40 | + content = "{}" |
| 41 | + |
| 42 | + ZMQ.send_multipart(requests_socket, [only(idents), "<IDS|MSG>", signature, header, parent_header, metadata, content]) |
| 43 | + ZMQ.recv_multipart(requests_socket, String) |
| 44 | + |
| 45 | + # Execute `42` |
| 46 | + idents = ["d2bd8e47-b2c9cd130d2967a19f52c1a3"] |
| 47 | + signature = "758c034ba5efb4fd7fd5a5600f913bc634739bf6a2c1e1d87e88b008706337bc" |
| 48 | + header = "{\"msg_id\": \"d2bd8e47-b2c9cd130d2967a19f52c1a3_3534705_1\", \"msg_type\": \"execute_request\", \"username\": \"james\", \"session\": \"d2bd8e47-b2c9cd130d2967a19f52c1a3\", \"date\": \"2025-02-20T22:29:49.835131Z\", \"version\": \"5.4\"}" |
| 49 | + parent_header = "{}" |
| 50 | + metadata = "{}" |
| 51 | + content = "{\"code\": \"42\", \"silent\": false, \"store_history\": true, \"user_expressions\": {}, \"allow_stdin\": true, \"stop_on_error\": true}" |
| 52 | + |
| 53 | + ZMQ.send_multipart(requests_socket, [only(idents), "<IDS|MSG>", signature, header, parent_header, metadata, content]) |
| 54 | + ZMQ.recv_multipart(requests_socket, String) |
| 55 | + |
| 56 | + # Execute `error(42)` |
| 57 | + idents = ["d2bd8e47-b2c9cd130d2967a19f52c1a3"] |
| 58 | + signature = "953702763b65d9b0505f34ae0eb195574b9c2c65eebedbfa8476150133649801" |
| 59 | + header = "{\"msg_id\": \"d2bd8e47-b2c9cd130d2967a19f52c1a3_3534705_2\", \"msg_type\": \"execute_request\", \"username\": \"james\", \"session\": \"d2bd8e47-b2c9cd130d2967a19f52c1a3\", \"date\": \"2025-02-20T22:29:50.320836Z\", \"version\": \"5.4\"}" |
| 60 | + parent_header = "{}" |
| 61 | + metadata = "{}" |
| 62 | + content = "{\"code\": \"error(42)\", \"silent\": false, \"store_history\": true, \"user_expressions\": {}, \"allow_stdin\": true, \"stop_on_error\": true}" |
| 63 | + |
| 64 | + ZMQ.send_multipart(requests_socket, [only(idents), "<IDS|MSG>", signature, header, parent_header, metadata, content]) |
| 65 | + ZMQ.recv_multipart(requests_socket, String) |
| 66 | + |
| 67 | + close(requests_socket) |
| 68 | + end |
| 69 | +end |
0 commit comments