sensu-spawn 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,24 +0,0 @@
1
- require "rspec"
2
- require "eventmachine"
3
-
4
- module Helpers
5
- def timer(delay, &callback)
6
- periodic_timer = EM::PeriodicTimer.new(delay) do
7
- callback.call
8
- periodic_timer.cancel
9
- end
10
- end
11
-
12
- def async_wrapper(&callback)
13
- EM.run do
14
- timer(10) do
15
- raise "test timed out"
16
- end
17
- callback.call
18
- end
19
- end
20
-
21
- def async_done
22
- EM.stop_event_loop
23
- end
24
- end
@@ -1,106 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "helpers")
2
- require "sensu/spawn"
3
-
4
- describe "Sensu::Spawn" do
5
- include Helpers
6
-
7
- it "can setup a process worker" do
8
- Sensu::Spawn.setup(:limit => 20)
9
- end
10
-
11
- it "can spawn a process" do
12
- async_wrapper do
13
- Sensu::Spawn.process("echo foo") do |output, status|
14
- expect(output).to eq("foo\n")
15
- expect(status).to eq(0)
16
- async_done
17
- end
18
- end
19
- end
20
-
21
- it "can spawn a process with output greater than 64KB" do |output, status|
22
- output_asset = "spec/assets/1MB"
23
- expected_output = IO.read(output_asset)
24
- async_wrapper do
25
- Sensu::Spawn.process("cat #{output_asset}") do |output, status|
26
- expect(output).to eq(expected_output)
27
- expect(status).to eq(0)
28
- async_done
29
- end
30
- end
31
- end
32
-
33
- it "can spawn a process with output greater than 64KB with a timeout" do |output, status|
34
- output_asset = "spec/assets/1MB"
35
- expected_output = IO.read(output_asset)
36
- async_wrapper do
37
- Sensu::Spawn.process("cat #{output_asset}", :timeout => 10) do |output, status|
38
- expect(output).to eq(expected_output)
39
- expect(status).to eq(0)
40
- async_done
41
- end
42
- end
43
- end
44
-
45
- it "can spawn a process with a non-zero exit status" do
46
- async_wrapper do
47
- Sensu::Spawn.process("echo foo && exit 1") do |output, status|
48
- expect(output).to eq("foo\n")
49
- expect(status).to eq(1)
50
- async_done
51
- end
52
- end
53
- end
54
-
55
- it "can spawn a process using an unknown command" do
56
- async_wrapper do
57
- Sensu::Spawn.process("unknown.command") do |output, status|
58
- expect(output).to include("unknown")
59
- expect(status).to eq(127)
60
- async_done
61
- end
62
- end
63
- end
64
-
65
- it "can spawn a process with a timeout" do
66
- async_wrapper do
67
- Sensu::Spawn.process("sleep 5", :timeout => 0.5) do |output, status|
68
- expect(output).to eq("Execution timed out")
69
- expect(status).to eq(2)
70
- async_done
71
- end
72
- end
73
- end
74
-
75
- it "can spawn a process that reads from STDIN" do
76
- async_wrapper do
77
- Sensu::Spawn.process("cat", :data => "bar") do |output, status|
78
- expect(output).to eq("bar")
79
- expect(status).to eq(0)
80
- async_done
81
- end
82
- end
83
- end
84
-
85
- it "can spawn a process that reads input greater than 64KB from STDIN" do |output, status|
86
- input_asset = IO.read("spec/assets/1MB")
87
- async_wrapper do
88
- Sensu::Spawn.process("cat", :data => input_asset) do |output, status|
89
- expect(output).to eq(input_asset)
90
- expect(status).to eq(0)
91
- async_done
92
- end
93
- end
94
- end
95
-
96
- it "can spawn a process that reads from STDIN and does not output to STDOUT" do
97
- input_asset = IO.read("spec/assets/1MB")
98
- async_wrapper do
99
- Sensu::Spawn.process("cat > /tmp/sensu-spawn-test", :data => input_asset) do |output, status|
100
- expect(output).to eq("")
101
- expect(status).to eq(0)
102
- async_done
103
- end
104
- end
105
- end
106
- end