circus-deployment 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/LICENSE +23 -0
  2. data/README.md +0 -0
  3. data/bin/circus +24 -0
  4. data/lib/bundler/circus_bundler.rb +24 -0
  5. data/lib/bundler/circus_util.rb +43 -0
  6. data/lib/bundler/patches.rb +18 -0
  7. data/lib/circus/act.rb +74 -0
  8. data/lib/circus/actstore_client.rb +30 -0
  9. data/lib/circus/agents/agent.rb +59 -0
  10. data/lib/circus/agents/client.rb +77 -0
  11. data/lib/circus/agents/connection.rb +76 -0
  12. data/lib/circus/agents/conversation.rb +17 -0
  13. data/lib/circus/agents/dbus_connection.rb +85 -0
  14. data/lib/circus/agents/dbus_logger.rb +34 -0
  15. data/lib/circus/agents/encoding.rb +32 -0
  16. data/lib/circus/agents/logger.rb +52 -0
  17. data/lib/circus/agents/params.rb +47 -0
  18. data/lib/circus/agents/ssh_connection.rb +120 -0
  19. data/lib/circus/application.rb +99 -0
  20. data/lib/circus/booth_client.rb +25 -0
  21. data/lib/circus/booth_tool.rb +98 -0
  22. data/lib/circus/cli.rb +147 -0
  23. data/lib/circus/clown_client.rb +27 -0
  24. data/lib/circus/connection_builder.rb +32 -0
  25. data/lib/circus/external_util.rb +14 -0
  26. data/lib/circus/local_config.rb +65 -0
  27. data/lib/circus/profiles/base.rb +115 -0
  28. data/lib/circus/profiles/django.rb +90 -0
  29. data/lib/circus/profiles/jekyll.rb +90 -0
  30. data/lib/circus/profiles/make_base.rb +17 -0
  31. data/lib/circus/profiles/pure_py.rb +46 -0
  32. data/lib/circus/profiles/pure_rb.rb +48 -0
  33. data/lib/circus/profiles/python_base.rb +39 -0
  34. data/lib/circus/profiles/rack.rb +59 -0
  35. data/lib/circus/profiles/ruby_base.rb +52 -0
  36. data/lib/circus/profiles/shell.rb +46 -0
  37. data/lib/circus/profiles.rb +10 -0
  38. data/lib/circus/repos/git.rb +42 -0
  39. data/lib/circus/repos/mercurial.rb +42 -0
  40. data/lib/circus/repos.rb +16 -0
  41. data/lib/circus/resource_allocator_client.rb +19 -0
  42. data/lib/circus/stdout_logger.rb +11 -0
  43. data/lib/circus/version.rb +3 -0
  44. data/lib/circus.rb +9 -0
  45. data/vendor/ruby-dbus/COPYING +504 -0
  46. data/vendor/ruby-dbus/ChangeLog +782 -0
  47. data/vendor/ruby-dbus/HOWTO-RELEASE +14 -0
  48. data/vendor/ruby-dbus/NEWS +104 -0
  49. data/vendor/ruby-dbus/README +53 -0
  50. data/vendor/ruby-dbus/Rakefile +47 -0
  51. data/vendor/ruby-dbus/doc/tutorial/src/00.index.page +12 -0
  52. data/vendor/ruby-dbus/doc/tutorial/src/10.intro.page +127 -0
  53. data/vendor/ruby-dbus/doc/tutorial/src/20.basic_client.page +174 -0
  54. data/vendor/ruby-dbus/doc/tutorial/src/30.service.page +121 -0
  55. data/vendor/ruby-dbus/doc/tutorial/src/default.css +129 -0
  56. data/vendor/ruby-dbus/doc/tutorial/src/default.template +46 -0
  57. data/vendor/ruby-dbus/examples/gdbus/gdbus +255 -0
  58. data/vendor/ruby-dbus/examples/gdbus/gdbus.glade +184 -0
  59. data/vendor/ruby-dbus/examples/gdbus/launch.sh +4 -0
  60. data/vendor/ruby-dbus/examples/no-introspect/nm-test.rb +21 -0
  61. data/vendor/ruby-dbus/examples/no-introspect/tracker-test.rb +16 -0
  62. data/vendor/ruby-dbus/examples/rhythmbox/playpause.rb +25 -0
  63. data/vendor/ruby-dbus/examples/service/call_service.rb +25 -0
  64. data/vendor/ruby-dbus/examples/service/service_newapi.rb +51 -0
  65. data/vendor/ruby-dbus/examples/simple/call_introspect.rb +34 -0
  66. data/vendor/ruby-dbus/examples/utils/listnames.rb +11 -0
  67. data/vendor/ruby-dbus/examples/utils/notify.rb +19 -0
  68. data/vendor/ruby-dbus/lib/dbus/auth.rb +156 -0
  69. data/vendor/ruby-dbus/lib/dbus/bus.rb +750 -0
  70. data/vendor/ruby-dbus/lib/dbus/export.rb +133 -0
  71. data/vendor/ruby-dbus/lib/dbus/introspect.rb +544 -0
  72. data/vendor/ruby-dbus/lib/dbus/marshall.rb +443 -0
  73. data/vendor/ruby-dbus/lib/dbus/matchrule.rb +100 -0
  74. data/vendor/ruby-dbus/lib/dbus/message.rb +293 -0
  75. data/vendor/ruby-dbus/lib/dbus/type.rb +222 -0
  76. data/vendor/ruby-dbus/lib/dbus.rb +89 -0
  77. data/vendor/ruby-dbus/ruby-dbus.gemspec +28 -0
  78. data/vendor/ruby-dbus/setup.rb +1585 -0
  79. data/vendor/ruby-dbus/test/Makefile +4 -0
  80. data/vendor/ruby-dbus/test/bus_driver_test.rb +21 -0
  81. data/vendor/ruby-dbus/test/server_robustness_test.rb +41 -0
  82. data/vendor/ruby-dbus/test/server_test.rb +44 -0
  83. data/vendor/ruby-dbus/test/service_newapi.rb +99 -0
  84. data/vendor/ruby-dbus/test/session_bus_test_manual.rb +20 -0
  85. data/vendor/ruby-dbus/test/signal_test.rb +57 -0
  86. data/vendor/ruby-dbus/test/t1 +4 -0
  87. data/vendor/ruby-dbus/test/t2.rb +66 -0
  88. data/vendor/ruby-dbus/test/t3-ticket27.rb +18 -0
  89. data/vendor/ruby-dbus/test/t5-report-dbus-interface.rb +58 -0
  90. data/vendor/ruby-dbus/test/t6-loop.rb +85 -0
  91. data/vendor/ruby-dbus/test/test_all +26 -0
  92. data/vendor/ruby-dbus/test/test_server +74 -0
  93. data/vendor/ruby-dbus/test/variant_test.rb +66 -0
  94. metadata +225 -0
@@ -0,0 +1,4 @@
1
+ check:
2
+ ./test_all
3
+ test: check
4
+ .PHONY: test check
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # Test the methods of the bus driver
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ def d(msg)
7
+ puts msg if $DEBUG
8
+ end
9
+
10
+ class BusDriverTest < Test::Unit::TestCase
11
+ def setup
12
+ @bus = DBus::SessionBus.instance
13
+ @svc = @bus.service("org.ruby.service")
14
+ end
15
+
16
+ def test_exists
17
+ assert @svc.exists?
18
+ nonsvc = @bus.service "org.ruby.nosuchservice"
19
+ assert ! nonsvc.exists?
20
+ end
21
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # Test that a server survives various error cases
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ class ServerRobustnessTest < Test::Unit::TestCase
7
+ def setup
8
+ @bus = DBus::SessionBus.instance
9
+ @svc = @bus.service("org.ruby.service")
10
+ end
11
+
12
+ # https://trac.luon.net/ruby-dbus/ticket/31
13
+ # the server should not crash
14
+ def test_no_such_path_with_introspection
15
+ obj = @svc.object "/org/ruby/NotMyInstance"
16
+ obj.introspect
17
+ assert false, "should have raised"
18
+ rescue DBus::Error => e
19
+ assert_no_match(/timeout/, e)
20
+ end
21
+
22
+ def test_no_such_path_without_introspection
23
+ obj = @svc.object "/org/ruby/NotMyInstance"
24
+ ifc = DBus::ProxyObjectInterface.new(obj, "org.ruby.SampleInterface")
25
+ ifc.define_method("the_answer", "out n:i")
26
+ ifc.the_answer
27
+ assert false, "should have raised"
28
+ rescue DBus::Error => e
29
+ assert_no_match(/timeout/, e)
30
+ end
31
+
32
+ def test_a_method_that_raises
33
+ obj = @svc.object "/org/ruby/MyInstance"
34
+ obj.introspect
35
+ obj.default_iface = "org.ruby.SampleInterface"
36
+ obj.will_raise
37
+ assert false, "should have raised"
38
+ rescue DBus::Error => e
39
+ assert_no_match(/timeout/, e)
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ # Test that a server survives various error cases
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ class Foo < DBus::Object
7
+ dbus_interface "org.ruby.ServerTest" do
8
+ dbus_signal :signal_without_arguments
9
+ dbus_signal :signal_with_argument, "epsilon:d"
10
+ end
11
+
12
+ dbus_signal :signal_without_interface
13
+ rescue DBus::Object::UndefinedInterface => e
14
+ # raised by the preceding signal declaration
15
+ end
16
+
17
+ class ServerTest < Test::Unit::TestCase
18
+ def setup
19
+ @bus = DBus::SessionBus.instance
20
+ @svc = @bus.request_service "org.ruby.server-test"
21
+ end
22
+
23
+ def teardown
24
+ @bus.proxy.ReleaseName "org.ruby.server-test"
25
+ end
26
+
27
+ def test_unexporting_an_object
28
+ obj = Foo.new "/org/ruby/Foo"
29
+ @svc.export obj
30
+ assert @svc.unexport(obj)
31
+ end
32
+
33
+ def test_unexporting_an_object_not_exported
34
+ obj = Foo.new "/org/ruby/Foo"
35
+ assert !@svc.unexport(obj)
36
+ end
37
+
38
+ def test_emiting_signals
39
+ obj = Foo.new "/org/ruby/Foo"
40
+ @svc.export obj
41
+ obj.signal_without_arguments
42
+ obj.signal_with_argument(-0.1)
43
+ end
44
+ end
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dbus'
4
+
5
+ def d(msg)
6
+ puts "#{$$} #{msg}" if $DEBUG
7
+ end
8
+
9
+ class Test < DBus::Object
10
+ # Create an interface aggregating all upcoming dbus_method defines.
11
+ dbus_interface "org.ruby.SampleInterface" do
12
+ dbus_method :hello, "in name:s, in name2:s" do |name, name2|
13
+ puts "hello(#{name}, #{name2})"
14
+ end
15
+
16
+ dbus_method :test_variant, "in stuff:v" do |variant|
17
+ p variant
18
+ end
19
+
20
+ dbus_method :bounce_variant, "in stuff:v, out chaff:v" do |variant|
21
+ [variant]
22
+ end
23
+
24
+ dbus_method :variant_size, "in stuff:v, out size:u" do |variant|
25
+ [variant.size]
26
+ end
27
+
28
+ dbus_method :the_answer, "out answer:i" do
29
+ 42
30
+ end
31
+
32
+ dbus_method :will_raise, "" do
33
+ raise "Handle this"
34
+ end
35
+
36
+ dbus_signal :SomethingJustHappened, "toto:s, tutu:u"
37
+ end
38
+
39
+ dbus_interface "org.ruby.AnotherInterface" do
40
+ dbus_method :ThatsALongMethodNameIThink do
41
+ puts "ThatsALongMethodNameIThink"
42
+ end
43
+ dbus_method :Reverse, "in instr:s, out outstr:s" do |instr|
44
+ outstr = instr.split(//).reverse.join
45
+ puts "got: #{instr}, replying: #{outstr}"
46
+ [outstr]
47
+ end
48
+ end
49
+
50
+ dbus_interface "org.ruby.Ticket30" do
51
+ dbus_method :Sybilla, 'in choices:av, out advice:s' do |choices|
52
+ ["Do #{choices[0]}"]
53
+ end
54
+ end
55
+
56
+ dbus_interface "org.ruby.Loop" do
57
+ # starts doing something long, but returns immediately
58
+ # and sends a signal when done
59
+ dbus_method :LongTaskBegin, 'in delay:i' do |delay|
60
+ # FIXME did not complain about mismatch between signature and block args
61
+ d "Long task began"
62
+ task = Thread.new do
63
+ d "Long task thread started (#{delay}s)"
64
+ sleep delay
65
+ d "Long task will signal end"
66
+ self.LongTaskEnd
67
+ end
68
+ task.abort_on_exception = true # protect from test case bugs
69
+ end
70
+
71
+ dbus_signal :LongTaskEnd
72
+ end
73
+ end
74
+
75
+ bus = DBus::SessionBus.instance
76
+ service = bus.request_service("org.ruby.service")
77
+ myobj = Test.new("/org/ruby/MyInstance")
78
+ service.export(myobj)
79
+
80
+ # introspect every other connection, Ticket #34
81
+ # (except the one that activates us - it has already emitted
82
+ # NOC by the time we run this. Therefore the test for #34 will not work
83
+ # by running t2.rb alone, one has to run t1 before it; 'rake' does it)
84
+ mr = DBus::MatchRule.new.from_s "type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged'"
85
+ bus.add_match(mr) do |msg|
86
+ new_unique_name = msg.params[2]
87
+ unless new_unique_name.empty?
88
+ # puts "RRRING #{new_unique_name}"
89
+ bus.introspect_data(new_unique_name, "/") do
90
+ # ignore the result
91
+ end
92
+ end
93
+ end
94
+
95
+ puts "listening"
96
+ main = DBus::Main.new
97
+ main << bus
98
+ main.run
99
+
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+ require "dbus"
4
+
5
+ def d(msg)
6
+ puts msg if $DEBUG
7
+ end
8
+
9
+ class SessionBusAddressTest < Test::Unit::TestCase
10
+ def setup
11
+ # test getting the session bus address even if unset in ENV (Issue#4)
12
+ ENV.delete "DBUS_SESSION_BUS_ADDRESS"
13
+ @bus = DBus::SessionBus.instance
14
+ @svc = @bus.service("org.freedesktop.DBus")
15
+ end
16
+
17
+ def test_connection
18
+ assert @svc.exists?
19
+ end
20
+ end
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ # Test the signal handlers
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ def d(msg)
7
+ puts "#{$$} #{msg}" if $DEBUG
8
+ end
9
+
10
+ class SignalHandlerTest < Test::Unit::TestCase
11
+ def setup
12
+ @session_bus = DBus::SessionBus.instance
13
+ svc = @session_bus.service("org.ruby.service")
14
+ @obj = svc.object("/org/ruby/MyInstance")
15
+ @obj.introspect # necessary
16
+ @obj.default_iface = "org.ruby.Loop"
17
+
18
+ @loop = DBus::Main.new
19
+ @loop << @session_bus
20
+ end
21
+
22
+ def teardown
23
+ # workaround for nonexisting remove_match
24
+ @session_bus.instance_variable_set(:@signal_matchrules, [])
25
+ end
26
+
27
+ # testing for commit 017c83 (kkaempf)
28
+ def test_calling_both_handlers
29
+ counter = 0
30
+
31
+ @obj.on_signal "LongTaskEnd" do
32
+ d "+10"
33
+ counter += 10
34
+ end
35
+ @obj.on_signal "LongTaskEnd" do
36
+ d "+1"
37
+ counter += 1
38
+ end
39
+
40
+ d "will begin"
41
+ @obj.LongTaskBegin 3
42
+
43
+ quitter = Thread.new do
44
+ d "sleep before quit"
45
+ # FIXME if we sleep for too long
46
+ # the socket will be drained and we deadlock in a select.
47
+ # It could be worked around by sending ourselves a Unix signal
48
+ # (with a dummy handler) to interrupt the select
49
+ sleep 1
50
+ d "will quit"
51
+ @loop.quit
52
+ end
53
+ @loop.run
54
+
55
+ assert_equal 11, counter
56
+ end
57
+ end
@@ -0,0 +1,4 @@
1
+ #! /bin/sh
2
+ SEND0="dbus-send --session --dest=org.ruby.service"
3
+ CALL="$SEND0 --type=method_call --print-reply"
4
+ $CALL /org/ruby/MyInstance org.ruby.AnotherInterface.Reverse string:Hello
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+ require "dbus"
4
+
5
+ class ValueTest < Test::Unit::TestCase
6
+ def setup
7
+ session_bus = DBus::SessionBus.instance
8
+ svc = session_bus.service("org.ruby.service")
9
+ @obj = svc.object("/org/ruby/MyInstance")
10
+ @obj.introspect # necessary
11
+ @obj.default_iface = "org.ruby.SampleInterface"
12
+ end
13
+
14
+ def test_passing_an_array_through_a_variant
15
+ # old explicit typing
16
+ @obj.test_variant(["as", ["coucou", "kuku"]])
17
+ # automatic typing
18
+ @obj.test_variant(["coucou", "kuku"])
19
+ @obj.test_variant(["saint", "was that a word or a signature?"])
20
+ end
21
+
22
+ def test_bouncing_a_variant
23
+ assert_equal "cuckoo", @obj.bounce_variant("cuckoo")[0]
24
+ assert_equal ["coucou", "kuku"], @obj.bounce_variant(["coucou", "kuku"])[0]
25
+ assert_equal [], @obj.bounce_variant([])[0]
26
+ empty_hash = {}
27
+ assert_equal empty_hash, @obj.bounce_variant(empty_hash)[0]
28
+ end
29
+
30
+ # these are ambiguous
31
+ def test_pairs_with_a_string
32
+
33
+ # deprecated
34
+ assert_equal "foo", @obj.bounce_variant(["s", "foo"])[0]
35
+
36
+ assert_equal "foo", @obj.bounce_variant(DBus.variant("s", "foo"))[0]
37
+ assert_equal "foo", @obj.bounce_variant([DBus.type("s"), "foo"])[0]
38
+
39
+ # does not work, because the server side forgets the explicit typing
40
+ # assert_equal ["s", "foo"], @obj.bounce_variant(["av", ["s", "foo"]])[0]
41
+ # assert_equal ["s", "foo"], @obj.bounce_variant(["as", ["s", "foo"]])[0]
42
+
43
+ # instead, use this to demonstrate that the variant is passed as expected
44
+ assert_equal 4, @obj.variant_size(["s", "four"])[0]
45
+ # "av" is the simplest thing that will work,
46
+ # shifting the heuristic from a pair to the individual items
47
+ assert_equal 2, @obj.variant_size(["av", ["s", "four"]])[0]
48
+ end
49
+
50
+ def test_marshalling_an_array_of_variants
51
+ # https://trac.luon.net/ruby-dbus/ticket/30
52
+ @obj.default_iface = "org.ruby.Ticket30"
53
+ choices = []
54
+ choices << ['s', 'Plan A']
55
+ choices << ['s', 'Plan B']
56
+ # old explicit typing
57
+ assert_equal "Do Plan A", @obj.Sybilla(choices)[0]
58
+ # automatic typing
59
+ assert_equal "Do Plan A", @obj.Sybilla(["Plan A", "Plan B"])[0]
60
+ end
61
+
62
+ def test_service_returning_nonarray
63
+ # "warning: default `to_a' will be obsolete"
64
+ @obj.the_answer
65
+ end
66
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # Test passing a particular struct array through a variant
3
+ # https://trac.luon.net/ruby-dbus/ticket/27
4
+ require "dbus"
5
+ session_bus = DBus::SessionBus.instance
6
+ svc = session_bus.service("org.ruby.service")
7
+ obj = svc.object("/org/ruby/MyInstance")
8
+ obj.introspect # necessary
9
+ obj.default_iface = "org.ruby.SampleInterface"
10
+ # The bug is probably alignment related so whether it triggers
11
+ # depends also on the combined length of service, interface,
12
+ # and method names. Luckily here it works out.
13
+ triple = ['a(uuu)', []]
14
+ obj.test_variant(triple)
15
+ quadruple = ['a(uuuu)', []] # a(uuu) works fine
16
+ # The bus disconnects us because of malformed message,
17
+ # code 12: DBUS_INVALID_TOO_MUCH_DATA
18
+ obj.test_variant(quadruple)
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # should report it missing on org.ruby.SampleInterface
3
+ # (on object...) instead of on DBus::Proxy::ObjectInterface
4
+ require "test/unit"
5
+ require "dbus"
6
+
7
+ class ErrMsgTest < Test::Unit::TestCase
8
+ def setup
9
+ session_bus = DBus::SessionBus.instance
10
+ svc = session_bus.service("org.ruby.service")
11
+ @obj = svc.object("/org/ruby/MyInstance")
12
+ @obj.introspect # necessary
13
+ @obj.default_iface = "org.ruby.SampleInterface"
14
+ end
15
+
16
+ def test_report_dbus_interface
17
+ begin
18
+ @obj.NoSuchMethod
19
+ # a specific exception...
20
+ rescue NameError => e
21
+ # mentioning DBus and the interface
22
+ assert_match(/DBus interface.*#{@obj.default_iface}/, e.to_s)
23
+ end
24
+ end
25
+
26
+ def test_report_short_struct
27
+ begin
28
+ @obj.test_variant ["(ss)", ["too few"] ]
29
+ rescue DBus::TypeException => e
30
+ assert_match(/1 elements but type info for 2/, e.to_s)
31
+ end
32
+ end
33
+
34
+ def test_report_long_struct
35
+ begin
36
+ @obj.test_variant ["(ss)", ["a", "b", "too many"] ]
37
+ rescue DBus::TypeException => e
38
+ assert_match(/3 elements but type info for 2/, e.to_s)
39
+ end
40
+ end
41
+
42
+ def test_report_nil
43
+ nils = [
44
+ ["(s)", [nil] ], # would get disconnected
45
+ ["i", nil ],
46
+ ["a{ss}", {"foo" => nil} ],
47
+ ]
48
+ nils.each do |has_nil|
49
+ begin
50
+ @obj.test_variant has_nil
51
+ rescue DBus::TypeException => e
52
+ # TODO want backtrace from the perspective of the caller:
53
+ # rescue/reraise in send_sync?
54
+ assert_match(/Cannot send nil/, e.to_s)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ # Test the main loop
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ def d(msg)
7
+ puts "#{$$} #{msg}" if $DEBUG
8
+ end
9
+
10
+ class MainLoopTest < Test::Unit::TestCase
11
+ def setup
12
+ @session_bus = DBus::SessionBus.instance
13
+ svc = @session_bus.service("org.ruby.service")
14
+ @obj = svc.object("/org/ruby/MyInstance")
15
+ @obj.introspect # necessary
16
+ @obj.default_iface = "org.ruby.Loop"
17
+
18
+ @loop = DBus::Main.new
19
+ @loop << @session_bus
20
+ end
21
+
22
+ def teardown
23
+ # workaround for nonexisting remove_match
24
+ @session_bus.instance_variable_set(:@signal_matchrules, [])
25
+ end
26
+
27
+ # Hack the library internals so that there is a delay between
28
+ # sending a DBus call and listening for its reply, so that
29
+ # the bus has a chance to join the server messages and a race is reproducible
30
+ def call_lazily
31
+ class << @session_bus
32
+ alias :wait_for_message_orig :wait_for_message
33
+ def wait_for_message_lazy
34
+ d "I am so lazy"
35
+ sleep 1 # Give the server+bus a chance to join the messages
36
+ wait_for_message_orig
37
+ end
38
+ alias :wait_for_message :wait_for_message_lazy
39
+ end
40
+
41
+ yield
42
+
43
+ # undo
44
+ class << @session_bus
45
+ remove_method :wait_for_message
46
+ remove_method :wait_for_message_lazy
47
+ alias :wait_for_message :wait_for_message_orig
48
+ end
49
+ end
50
+
51
+ def test_loop_quit(delay = 1)
52
+ @obj.on_signal "LongTaskEnd" do
53
+ d "Telling loop to quit"
54
+ @loop.quit
55
+ end
56
+
57
+ call_lazily do
58
+ # The method will sleep the requested amount of seconds
59
+ # (in another thread) before signalling LongTaskEnd
60
+ @obj.LongTaskBegin delay
61
+ end
62
+
63
+ # this thread will make the test fail if @loop.run does not return
64
+ dynamite = Thread.new do
65
+ d "Dynamite burning"
66
+ sleep 2
67
+ d "Dynamite explodes"
68
+ # We need to raise in the main thread.
69
+ # Simply raising here means the exception is ignored
70
+ # (until dynamite.join which we don't call) or
71
+ # (if abort_on_exception is set) it terminates the whole script.
72
+ Thread.main.raise RuntimeError, "The main loop did not quit in time"
73
+ end
74
+
75
+ @loop.run
76
+ d "Defusing dynamite"
77
+ # if we get here, defuse the bomb
78
+ dynamite.exit
79
+ end
80
+
81
+ # https://bugzilla.novell.com/show_bug.cgi?id=537401
82
+ def test_loop_drained_socket
83
+ test_loop_quit 0
84
+ end
85
+ end
@@ -0,0 +1,26 @@
1
+ #! /bin/bash
2
+ # run all applicable test cases with proper setup
3
+ # $0 [-a: all, even failing]
4
+ # $0 ./a_single_testcase
5
+ if [ "$1" = "" ]; then
6
+ : ${CASES:=./t[01234-9]* ./*_test.rb}
7
+ elif [ "$1" = "-a" ]; then
8
+ : ${CASES:=./t? ./t*-* ./*_test.rb}
9
+ OPTS=-k
10
+ else
11
+ : ${CASES:=$@}
12
+ fi
13
+ CASES_A=($CASES) # make array
14
+ CASES_A=(${CASES_A[@]/*~/}) # exclude backup files
15
+ if ! which python >/dev/null; then
16
+ echo >&2 "Python not found, skipping those tests"
17
+ CASES_A=(${CASES_A[@]/*.py/}) # exclude python files
18
+ fi
19
+
20
+ #export DBUS_VERBOSE=1
21
+ #export RUBYOPT="-d"
22
+ export RUBYOPT="$RUBYOPT -w"
23
+ RUBYLIB=../lib ./test_server $OPTS \
24
+ ./service_newapi.rb \
25
+ -- \
26
+ ${CASES_A[@]}
@@ -0,0 +1,74 @@
1
+ #! /bin/sh
2
+ # A wrapper for DBus tests
3
+ # Sets up a private session bus and calls all its arguments in turn
4
+ # exiting on first failure
5
+ # $0 server [-k] [arg1 arg2...] -- test1 test2...
6
+ set -o errexit
7
+
8
+ KEEP_GOING=false
9
+ if [ "$1" = "-k" ]; then
10
+ KEEP_GOING=true
11
+ shift
12
+ fi
13
+
14
+ while [ "$1" != "--" ]; do
15
+ SERVER="$SERVER $1"
16
+ shift
17
+ done
18
+ shift # --
19
+
20
+ # This launches the bus daemon,
21
+ # exports DBUS_SESSION_BUS_ADDRESS and sets DBUS_SESSION_BUS_PID
22
+ my_dbus_launch () {
23
+ # reimplementing dbus-launch because it is in dbus-1-x11.rpm
24
+ PF=`mktemp dbus.pid.XXXXXX` || exit
25
+ AF=`mktemp dbus.addr.XXXXXX` || exit
26
+ RM_FILES="$RM_FILES $PF $AF"
27
+
28
+ dbus-daemon --session --print-address=3 3>$AF --print-pid=4 4>$PF &
29
+ # wait for the daemon to print the info
30
+ TRIES=0
31
+ while [ ! -s $AF -o ! -s $PF ]; do
32
+ sleep 0.1
33
+ TRIES=`expr $TRIES + 1`
34
+ if [ $TRIES -gt 100 ]; then echo "dbus-daemon failed?"; exit 1; fi
35
+ done
36
+ DBUS_SESSION_BUS_PID=$(cat $PF)
37
+ export DBUS_SESSION_BUS_ADDRESS=$(cat $AF)
38
+ KILLS="$KILLS $DBUS_SESSION_BUS_PID"
39
+ # dbus-monitor &
40
+ }
41
+
42
+ setup_activation () {
43
+ SDIR=$XDG_DATA_DIRS/dbus-1/services
44
+ mkdir -p $SDIR
45
+ cat <<EOF > $SDIR/test.service
46
+ [D-BUS Service]
47
+ Name=org.ruby.service
48
+ Exec=$SERVER
49
+ EOF
50
+ }
51
+
52
+ run_server () {
53
+ echo -n "Hey, server, get on da bus... "
54
+ # start the server
55
+ $SERVER & sleep 3
56
+ echo "off we go!"
57
+ }
58
+
59
+ export XDG_DATA_DIRS=`mktemp -d dbus.activation.XXXXXX`
60
+ RM_FILES="$RM_FILES $XDG_DATA_DIRS"
61
+ my_dbus_launch
62
+ setup_activation
63
+ #run_server
64
+
65
+ # Clean up at exit. This will also kill the server.
66
+ trap "kill \$KILLS; rm -rf \$RM_FILES" EXIT TERM INT
67
+
68
+ while [ -n "$1" ]; do
69
+ echo Running $1
70
+ $1 || $KEEP_GOING
71
+ shift
72
+ done
73
+
74
+ echo Done
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ # Test marshalling variants according to ruby types
3
+ require "test/unit"
4
+ require "dbus"
5
+
6
+ class VariantTest < Test::Unit::TestCase
7
+ def setup
8
+ @bus = DBus::SessionBus.instance
9
+ @svc = @bus.service("org.ruby.service")
10
+ end
11
+
12
+ def make_variant(a)
13
+ DBus::PacketMarshaller.make_variant(a)
14
+ end
15
+
16
+ def test_make_variant_scalar
17
+ # special case: do not fail immediately, marshaller will do that
18
+ assert_equal ["b", nil], make_variant(nil)
19
+
20
+ assert_equal ["b", true], make_variant(true)
21
+ # Integers
22
+ # no byte
23
+ assert_equal ["i", 42], make_variant(42)
24
+ # 3_000_000_000 can be u or x.
25
+ # less specific test: just run it thru a loopback
26
+ assert_equal ["x", 3_000_000_000], make_variant(3_000_000_000)
27
+ assert_equal ["x", 5_000_000_000], make_variant(5_000_000_000)
28
+
29
+ assert_equal ["d", 3.14], make_variant(3.14)
30
+
31
+ assert_equal ["s", "foo"], make_variant("foo")
32
+ assert_equal ["s", "bar"], make_variant(:bar)
33
+
34
+ # left: strruct, array, dict
35
+ # object path: detect exported objects?, signature
36
+
37
+ # # by Ruby types
38
+ # class Foo
39
+ # end
40
+ # make_variant(Foo.new)
41
+ # if we don;t understand a class, the error should be informative -> new exception
42
+ end
43
+
44
+ def test_make_variant_array
45
+ ai = [1, 2, 3]
46
+ # as = ["one", "two", "three"]
47
+ # which?
48
+ # assert_equal ["ai", [1, 2, 3]], make_variant(ai)
49
+ assert_equal ["av", [["i", 1],
50
+ ["i", 2],
51
+ ["i", 3]]], make_variant(ai)
52
+ a0 = []
53
+ assert_equal ["av", []], make_variant(a0)
54
+
55
+ end
56
+
57
+ def test_make_variant_hash
58
+ h = {"k1" => "v1", "k2" => "v2"}
59
+ assert_equal ["a{sv}", {
60
+ "k1" => ["s", "v1"],
61
+ "k2" => ["s", "v2"],
62
+ }], make_variant(h)
63
+ h0 = {}
64
+ assert_equal ["a{sv}", {}], make_variant(h0)
65
+ end
66
+ end