Add option to modify HTTP pool size
[akkoma] / test / pleroma / http / adapter_helper_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.HTTP.AdapterHelperTest do
6 use Pleroma.DataCase, async: true
7 alias Pleroma.HTTP.AdapterHelper
8
9 describe "format_proxy/1" do
10 test "with nil" do
11 assert AdapterHelper.format_proxy(nil) == nil
12 end
13
14 test "with string" do
15 assert AdapterHelper.format_proxy("http://127.0.0.1:8123") == {:http, "127.0.0.1", 8123, []}
16 end
17
18 test "localhost with port" do
19 assert AdapterHelper.format_proxy("https://localhost:8123") ==
20 {:https, "localhost", 8123, []}
21 end
22
23 test "tuple" do
24 assert AdapterHelper.format_proxy({:http, "localhost", 9050}) ==
25 {:http, "localhost", 9050, []}
26 end
27 end
28
29 describe "maybe_add_proxy_pool/1" do
30 test "should do nothing with nil" do
31 assert AdapterHelper.maybe_add_proxy_pool([], nil) == []
32 end
33
34 test "should create pools" do
35 assert AdapterHelper.maybe_add_proxy_pool([], "proxy") == [
36 pools: %{default: [conn_opts: [proxy: "proxy"]]}
37 ]
38 end
39
40 test "should not override conn_opts if set" do
41 assert AdapterHelper.maybe_add_proxy_pool(
42 [pools: %{default: [conn_opts: [already: "set"]]}],
43 "proxy"
44 ) == [
45 pools: %{default: [conn_opts: [proxy: "proxy", already: "set"]]}
46 ]
47 end
48 end
49
50 describe "timeout settings" do
51 test "should default to 5000/15000" do
52 options = AdapterHelper.options(%URI{host: 'somewhere'})
53 assert options[:pool_timeout] == 5000
54 assert options[:receive_timeout] == 15_000
55 end
56
57 test "pool_timeout should be overridden by :http, :pool_timeout" do
58 clear_config([:http, :pool_timeout], 10_000)
59 options = AdapterHelper.options(%URI{host: 'somewhere'})
60 assert options[:pool_timeout] == 10_000
61 end
62
63 test "receive_timeout should be overridden by :http, :receive_timeout" do
64 clear_config([:http, :receive_timeout], 20_000)
65 options = AdapterHelper.options(%URI{host: 'somewhere'})
66 assert options[:receive_timeout] == 20_000
67 end
68 end
69
70 describe "pool size settings" do
71 test "should get set" do
72 options = AdapterHelper.add_pool_size([], 50)
73 assert options[:pools][:default][:size] == 50
74 end
75 end
76 end