Skip to content

Commit 2354227

Browse files
authored
Merge pull request #150 from bombaywalla/call-test
Improved flaky test
2 parents 75f5c1d + 5ceeb8b commit 2354227

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Improved flaky test #150
6+
57
## 0.66.1
68

79
- Improve plan behavior prompt. #139

test/eca/features/chat_test.clj

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
(loop [remaining (- deadline (System/currentTimeMillis))]
3030
(when (pos? remaining)
3131
(try
32-
(Thread/sleep remaining)
32+
(Thread/sleep (long remaining))
3333
(catch InterruptedException _))
3434
(recur (- deadline (System/currentTimeMillis)))))))
3535

@@ -258,15 +258,16 @@
258258
:call-tool-mock
259259
;; Ensure that the tools complete in the 3-2-1 order by adjusting sleep times
260260
(fn [name & _others]
261+
;; When this is called, we are already in a future.
261262
(case name
262263

263264
"ro_tool_1"
264-
(do (deep-sleep 300)
265+
(do (deep-sleep 900)
265266
{:error false
266267
:contents [{:type :text :content "RO tool call 1 result"}]})
267268

268269
"ro_tool_2"
269-
(do (deep-sleep 200)
270+
(do (deep-sleep 600)
270271
{:error false
271272
:contents [{:type :text :content "RO tool call 2 result"}]})
272273

@@ -329,10 +330,13 @@
329330
{:role :system :content {:type :progress :state :finished}}]}
330331
(h/messages))))))
331332

332-
(deftest tool-calls-with-prompt-stop
333+
(deftest tool-calls-with-prompt-stop-test
333334
(testing "Three concurrent tool calls. Stopped before they all finished. Tool call 3 finishes. Calls 1,2 reject."
334335
(h/reset-components!)
335-
(let [{:keys [chat-id]}
336+
(let [wait-for-tool3 (promise)
337+
wait-for-tool2 (promise)
338+
wait-for-stop (promise)
339+
{:keys [chat-id]}
336340
(complete!
337341
{:message "Run 3 read-only tool calls simultaneously."}
338342
{:api-mock
@@ -344,27 +348,38 @@
344348
(on-prepare-tool-call {:id "call-1" :name "ro_tool_1" :arguments-text ""})
345349
(on-prepare-tool-call {:id "call-2" :name "ro_tool_2" :arguments-text ""})
346350
(on-prepare-tool-call {:id "call-3" :name "ro_tool_3" :arguments-text ""})
347-
(future (Thread/sleep 200)
348-
(f.chat/prompt-stop {:chat-id chat-id} (h/db*) (h/messenger) (h/metrics)))
351+
(future (Thread/sleep 400)
352+
(when (= :timeout (deref wait-for-tool3 10000 :timeout))
353+
(println "tool-calls-with-prompt-stop-test: deref in prompt stop future timed out"))
354+
(Thread/sleep 50)
355+
(f.chat/prompt-stop {:chat-id chat-id} (h/db*) (h/messenger) (h/metrics))
356+
(deliver wait-for-stop true))
349357
(on-tools-called [{:id "call-1" :name "ro_tool_1" :arguments {}}
350358
{:id "call-2" :name "ro_tool_2" :arguments {}}
351359
{:id "call-3" :name "ro_tool_3" :arguments {}}])))
352360
:call-tool-mock
353361
(fn [name & _others]
362+
;; When this is called, we are already in a future
354363
(case name
355364

356365
"ro_tool_1"
357-
(do (deep-sleep 350)
366+
(do (deep-sleep 1000)
367+
(when (= :timeout (deref wait-for-tool2 10000 :timeout))
368+
(println "tool-calls-with-prompt-stop-test: deref in tool 1 timed out"))
358369
{:error false
359370
:contents [{:type :text :content "RO tool call 1 result"}]})
360371

361372
"ro_tool_2"
362-
(do (deep-sleep 300)
373+
(do (deep-sleep 800)
374+
(when (= :timeout (deref wait-for-stop 10000 :timeout))
375+
(println "tool-calls-with-prompt-stop-test: deref in tool 2 timed out"))
376+
(deliver wait-for-tool2 true)
363377
{:error false
364378
:contents [{:type :text :content "RO tool call 2 result"}]})
365379

366380
"ro_tool_3"
367-
(do (deep-sleep 100)
381+
(do (deep-sleep 200)
382+
(deliver wait-for-tool3 true)
368383
{:error false
369384
:contents [{:type :text :content "RO tool call 3 result"}]})))})]
370385
(is (match? {chat-id

0 commit comments

Comments
 (0)