|
7 | 7 | expect(EppoClient::VERSION).not_to be nil
|
8 | 8 | end
|
9 | 9 |
|
| 10 | + describe "wait_for_initialization()" do |
| 11 | + before :each do |
| 12 | + EppoClient::Client.instance.init(EppoClient::Config.new("test-api-key", base_url: "http://127.0.0.1:8378/ufc/api")) |
| 13 | + @client = EppoClient::Client.instance |
| 14 | + end |
| 15 | + |
| 16 | + it "has default timeout" do |
| 17 | + @client.wait_for_initialization() |
| 18 | + |
| 19 | + expect(@client.configuration).not_to be_nil |
| 20 | + end |
| 21 | + |
| 22 | + it "allows 0 timeout" do |
| 23 | + @client.wait_for_initialization(0) |
| 24 | + |
| 25 | + # Local configuration fetching is so fast that sometimes it |
| 26 | + # succeeds before we call wait_for_initialization(). Therefore, |
| 27 | + # we treat absense of errors as a sign of success here. |
| 28 | + end |
| 29 | + |
| 30 | + it "allows fractional timeout" do |
| 31 | + @client.wait_for_initialization(0.5) |
| 32 | + |
| 33 | + expect(@client.configuration).not_to be_nil |
| 34 | + end |
| 35 | + |
| 36 | + it "timeouts with bad URL" do |
| 37 | + EppoClient::Client.instance.init(EppoClient::Config.new("test-api-key", base_url: "http://127.0.0.1:8378/undefined/api")) |
| 38 | + @client = EppoClient::Client.instance |
| 39 | + |
| 40 | + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) |
| 41 | + @client.wait_for_initialization(0.2) |
| 42 | + stop = Process.clock_gettime(Process::CLOCK_MONOTONIC) |
| 43 | + |
| 44 | + expect(@client.configuration).to be_nil |
| 45 | + # shall wait at least for timeout |
| 46 | + expect(stop - start).to be >= 0.2 |
| 47 | + end |
| 48 | + end |
| 49 | + |
10 | 50 | describe "configuration()" do
|
11 | 51 | it "allows getting configuration" do
|
12 | 52 | init_client_for "ufc"
|
|
0 commit comments