|
385 | 385 | _ (server/start server nil) |
386 | 386 | req (p/promise (server/send-request server "req" {:body "foo"})) |
387 | 387 | client-rcvd-msg (h/assert-take output-ch)] |
388 | | - (async/put! input-ch (lsp.responses/response (:id client-rcvd-msg) {:result :processed |
389 | | - :value 1})) |
390 | | - (is (= {:result :processed |
391 | | - :value 2} |
| 388 | + (async/put! input-ch (lsp.responses/response (:id client-rcvd-msg) {:result "good"})) |
| 389 | + (is (= {:result :client-success |
| 390 | + :value 2 |
| 391 | + :resp {:result "good"}} |
392 | 392 | (-> req |
393 | | - (p/timeout 1000 {:result :test-timeout |
394 | | - :value 1}) |
| 393 | + (p/then (fn [resp] {:result :client-success |
| 394 | + :value 1 |
| 395 | + :resp resp})) |
| 396 | + (p/catch (fn [error-resp-ex] {:result :client-error |
| 397 | + :value 10 |
| 398 | + :resp (ex-data error-resp-ex)})) |
| 399 | + (p/timeout 1000 {:result :timeout |
| 400 | + :value 100}) |
395 | 401 | (p/then #(update % :value inc)) |
396 | 402 | (deref)))) |
397 | 403 | (is (p/done? req)) |
398 | 404 | (is (p/resolved? req)) |
399 | 405 | (is (not (p/rejected? req))) |
400 | 406 | (is (not (p/cancelled? req))) |
401 | 407 | (server/shutdown server))) |
| 408 | + (testing "after timeout" |
| 409 | + (let [input-ch (async/chan 3) |
| 410 | + output-ch (async/chan 3) |
| 411 | + server (server/chan-server {:output-ch output-ch |
| 412 | + :input-ch input-ch}) |
| 413 | + _ (server/start server nil) |
| 414 | + req (p/promise (server/send-request server "req" {:body "foo"}))] |
| 415 | + (is (= {:result :timeout |
| 416 | + :value 101} |
| 417 | + (-> req |
| 418 | + (p/then (fn [resp] {:result :client-success |
| 419 | + :value 1 |
| 420 | + :resp resp})) |
| 421 | + (p/catch (fn [error-resp-ex] {:result :client-error |
| 422 | + :value 10 |
| 423 | + :resp (ex-data error-resp-ex)})) |
| 424 | + (p/timeout 300 {:result :timeout |
| 425 | + :value 100}) |
| 426 | + (p/then #(update % :value inc)) |
| 427 | + (deref)))) |
| 428 | + (is (not (p/done? req))) |
| 429 | + (is (not (p/resolved? req))) |
| 430 | + (is (not (p/rejected? req))) |
| 431 | + (is (not (p/cancelled? req))) |
| 432 | + (server/shutdown server))) |
| 433 | + (testing "after client error" |
| 434 | + (let [input-ch (async/chan 3) |
| 435 | + output-ch (async/chan 3) |
| 436 | + server (server/chan-server {:output-ch output-ch |
| 437 | + :input-ch input-ch}) |
| 438 | + _ (server/start server nil) |
| 439 | + req (p/promise (server/send-request server "req" {:body "foo"})) |
| 440 | + client-rcvd-msg (h/assert-take output-ch)] |
| 441 | + (async/put! input-ch |
| 442 | + (-> (lsp.responses/response (:id client-rcvd-msg)) |
| 443 | + (lsp.responses/error {:code 1234 |
| 444 | + :message "Something bad" |
| 445 | + :data {:body "foo"}}))) |
| 446 | + (is (= {:result :client-error |
| 447 | + :value 11 |
| 448 | + :resp {:jsonrpc "2.0", |
| 449 | + :id 1, |
| 450 | + :error {:code 1234, |
| 451 | + :message "Something bad", |
| 452 | + :data {:body "foo"}}}} |
| 453 | + (-> req |
| 454 | + (p/then (fn [resp] {:result :client-success |
| 455 | + :value 1 |
| 456 | + :resp resp})) |
| 457 | + (p/catch (fn [error-resp-ex] {:result :client-error |
| 458 | + :value 10 |
| 459 | + :resp (ex-data error-resp-ex)})) |
| 460 | + (p/timeout 1000 {:result :timeout |
| 461 | + :value 100}) |
| 462 | + (p/then #(update % :value inc)) |
| 463 | + (deref)))) |
| 464 | + (is (p/done? req)) |
| 465 | + (is (not (p/resolved? req))) |
| 466 | + (is (p/rejected? req)) |
| 467 | + (is (not (p/cancelled? req))) |
| 468 | + (server/shutdown server))) |
402 | 469 | (testing "after cancellation" |
403 | 470 | (let [input-ch (async/chan 3) |
404 | 471 | output-ch (async/chan 3) |
|
0 commit comments