spec/timber/log_devices/http_spec.rb in timber-2.0.24 vs spec/timber/log_devices/http_spec.rb in timber-2.1.0.rc1

- old
+ new

@@ -40,11 +40,11 @@ context "with a low batch size" do let(:http) { described_class.new("MYKEY", :batch_size => 2) } it "should attempt a delivery when the limit is exceeded" do http.write("test") - expect(http).to receive(:flush).exactly(1).times + expect(http).to receive(:flush_async).exactly(1).times http.write("my log message") expect(http).to receive(:flush).exactly(1).times http.close end end @@ -74,17 +74,33 @@ # Testing a private method because it helps break down our tests describe "#flush" do let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) } - it "should add a request to the queue" do + it "should deliver the request" do http = described_class.new("MYKEY", flush_continuously: false) log_entry = Timber::LogEntry.new("INFO", time, nil, "test log message 1", nil, nil) http.write(log_entry) log_entry = Timber::LogEntry.new("INFO", time, nil, "test log message 2", nil, nil) http.write(log_entry) + expect(http).to receive(:flush_async).exactly(2).times http.send(:flush) + http.close + end + end + + # Testing a private method because it helps break down our tests + describe "#flush_async" do + let(:time) { Time.utc(2016, 9, 1, 12, 0, 0) } + + it "should add a request to the queue" do + http = described_class.new("MYKEY", flush_continuously: false) + log_entry = Timber::LogEntry.new("INFO", time, nil, "test log message 1", nil, nil) + http.write(log_entry) + log_entry = Timber::LogEntry.new("INFO", time, nil, "test log message 2", nil, nil) + http.write(log_entry) + http.send(:flush_async) request_queue = http.instance_variable_get(:@request_queue) request = request_queue.deq expect(request).to be_kind_of(Net::HTTP::Post) expect(request.body).to start_with("\x92\x85\xA5level\xA4INFO\xA2dt\xBB2016-09-01T12:00:00.000000Z\xA7message\xB2test log message 1\xA7context\x81".force_encoding("ASCII-8BIT")) @@ -96,11 +112,11 @@ # Testing a private method because it helps break down our tests describe "#intervaled_flush" do it "should start a intervaled flush thread and flush on an interval" do http = described_class.new("MYKEY", flush_interval: 0.1) http.send(:ensure_flush_threads_are_started) - expect(http).to receive(:flush).exactly(2).times - sleep 0.15 # too fast! + expect(http).to receive(:flush_async).at_least(3).times + sleep 1.1 # iterations check every 0.5 seconds http.close end end # Outlet \ No newline at end of file