|
29 | 29 | (loop [remaining (- deadline (System/currentTimeMillis))] |
30 | 30 | (when (pos? remaining) |
31 | 31 | (try |
32 | | - (Thread/sleep remaining) |
| 32 | + (Thread/sleep (long remaining)) |
33 | 33 | (catch InterruptedException _)) |
34 | 34 | (recur (- deadline (System/currentTimeMillis))))))) |
35 | 35 |
|
|
329 | 329 | {:role :system :content {:type :progress :state :finished}}]} |
330 | 330 | (h/messages)))))) |
331 | 331 |
|
332 | | -(deftest tool-calls-with-prompt-stop |
| 332 | +(deftest tool-calls-with-prompt-stop-test |
333 | 333 | (testing "Three concurrent tool calls. Stopped before they all finished. Tool call 3 finishes. Calls 1,2 reject." |
334 | 334 | (h/reset-components!) |
335 | | - (let [{:keys [chat-id]} |
| 335 | + (let [wait-for-tool3 (promise) |
| 336 | + wait-for-tool2 (promise) |
| 337 | + wait-for-stop (promise) |
| 338 | + {:keys [chat-id]} |
336 | 339 | (complete! |
337 | 340 | {:message "Run 3 read-only tool calls simultaneously."} |
338 | 341 | {:api-mock |
|
345 | 348 | (on-prepare-tool-call {:id "call-2" :name "ro_tool_2" :arguments-text ""}) |
346 | 349 | (on-prepare-tool-call {:id "call-3" :name "ro_tool_3" :arguments-text ""}) |
347 | 350 | (future (Thread/sleep 200) |
348 | | - (f.chat/prompt-stop {:chat-id chat-id} (h/db*) (h/messenger) (h/metrics))) |
| 351 | + (deref wait-for-tool3) |
| 352 | + (Thread/sleep 50) |
| 353 | + (f.chat/prompt-stop {:chat-id chat-id} (h/db*) (h/messenger) (h/metrics)) |
| 354 | + (deliver wait-for-stop true)) |
349 | 355 | (on-tools-called [{:id "call-1" :name "ro_tool_1" :arguments {}} |
350 | 356 | {:id "call-2" :name "ro_tool_2" :arguments {}} |
351 | 357 | {:id "call-3" :name "ro_tool_3" :arguments {}}]))) |
|
355 | 361 |
|
356 | 362 | "ro_tool_1" |
357 | 363 | (do (deep-sleep 350) |
| 364 | + (deref wait-for-tool2) |
358 | 365 | {:error false |
359 | 366 | :contents [{:type :text :content "RO tool call 1 result"}]}) |
360 | 367 |
|
361 | 368 | "ro_tool_2" |
362 | 369 | (do (deep-sleep 300) |
| 370 | + (deref wait-for-stop) |
| 371 | + (deliver wait-for-tool2 true) |
363 | 372 | {:error false |
364 | 373 | :contents [{:type :text :content "RO tool call 2 result"}]}) |
365 | 374 |
|
366 | 375 | "ro_tool_3" |
367 | 376 | (do (deep-sleep 100) |
| 377 | + (deliver wait-for-tool3 true) |
368 | 378 | {:error false |
369 | 379 | :contents [{:type :text :content "RO tool call 3 result"}]})))})] |
370 | 380 | (is (match? {chat-id |
|
0 commit comments