appsignal 0.10.6 → 0.11.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,44 +0,0 @@
1
- module Appsignal
2
- class Pipe
3
- attr_reader :reader, :writer, :listener
4
-
5
- def initialize
6
- Appsignal.logger.debug "Initializing pipe in #{$$}"
7
- @reader, @writer = IO.pipe
8
- @listener = Thread.new do
9
- loop do
10
- Appsignal.agent.enqueue(Marshal::load(@reader))
11
- end
12
- end
13
- @listening = true
14
- end
15
-
16
- def write(transaction)
17
- Marshal::dump(transaction, @writer)
18
- rescue IOError
19
- Appsignal.logger.debug "Broken pipe in #{$$}"
20
- Appsignal.agent.shutdown(true, 'broken pipe')
21
- end
22
-
23
- def stop_listening!
24
- Thread.kill(@listener)
25
- @reader.close unless @reader.closed?
26
- @listening = false
27
- end
28
-
29
- def listening?
30
- !! @listening
31
- end
32
-
33
- class << self
34
- def init
35
- Thread.current[:appsignal_pipe] = Appsignal::Pipe.new
36
- end
37
-
38
- def current
39
- Thread.current[:appsignal_pipe]
40
- end
41
- end
42
- end
43
- end
44
-
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Appsignal::Pipe do
4
- before :all do
5
- Appsignal::Pipe.init
6
- end
7
- let(:agent) { double }
8
-
9
- subject { Appsignal::Pipe.current }
10
-
11
- its(:reader) { should be_instance_of(IO) }
12
- its(:writer) { should be_instance_of(IO) }
13
- its(:listener) { should be_instance_of(Thread) }
14
- its(:listening?) { should be_true }
15
-
16
- describe "#write" do
17
- context "with a regular request" do
18
- let(:transaction) { regular_transaction }
19
-
20
- it "should dump" do
21
- Marshal.should_receive(:dump)
22
- end
23
- end
24
-
25
- context "when the pipe is closed" do
26
- let(:transaction) { regular_transaction }
27
- before { Appsignal.stub(:agent => agent) }
28
-
29
- it "should shutdown" do
30
- Appsignal::Pipe.current.writer.close
31
- agent.should_receive(:shutdown)
32
- end
33
- end
34
-
35
- after { Appsignal::Pipe.current.write(transaction) }
36
- end
37
-
38
- describe "#stop_listening!" do
39
- before do
40
- subject.stop_listening!
41
- sleep 0.1
42
- end
43
-
44
- it "should have closed the reader" do
45
- subject.reader.closed?.should be_true
46
- end
47
-
48
- it "should have killed the listener thread" do
49
- subject.listener.alive?.should be_false
50
- end
51
-
52
- it "should not crash when called twice" do
53
- expect { subject.stop_listening! }.not_to raise_error
54
- end
55
-
56
- it "should know it's not listening anymore" do
57
- subject.listening?.should be_false
58
- end
59
- end
60
- end