xmpp4r 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CHANGELOG +8 -0
  2. data/README.rdoc +4 -1
  3. data/Rakefile +10 -20
  4. data/data/doc/xmpp4r/examples/advanced/versionpoll.rb +20 -1
  5. data/lib/xmpp4r/bytestreams/helper/ibb/target.rb +7 -0
  6. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb +7 -1
  7. data/lib/xmpp4r/callbacks.rb +9 -0
  8. data/lib/xmpp4r/caps/c.rb +14 -0
  9. data/lib/xmpp4r/caps/helper/helper.rb +1 -4
  10. data/lib/xmpp4r/client.rb +42 -15
  11. data/lib/xmpp4r/connection.rb +7 -3
  12. data/lib/xmpp4r/debuglog.rb +22 -1
  13. data/lib/xmpp4r/discovery.rb +1 -0
  14. data/lib/xmpp4r/discovery/helper/helper.rb +58 -0
  15. data/lib/xmpp4r/discovery/iq/discoinfo.rb +2 -2
  16. data/lib/xmpp4r/discovery/iq/discoitems.rb +2 -2
  17. data/lib/xmpp4r/errors.rb +5 -2
  18. data/lib/xmpp4r/httpbinding/client.rb +9 -19
  19. data/lib/xmpp4r/last.rb +2 -0
  20. data/lib/xmpp4r/last/helper/helper.rb +37 -0
  21. data/lib/xmpp4r/last/iq/last.rb +67 -0
  22. data/lib/xmpp4r/location.rb +2 -0
  23. data/lib/xmpp4r/location/helper/helper.rb +56 -0
  24. data/lib/xmpp4r/location/location.rb +179 -0
  25. data/lib/xmpp4r/message.rb +32 -0
  26. data/lib/xmpp4r/presence.rb +1 -1
  27. data/lib/xmpp4r/pubsub/children/configuration.rb +1 -1
  28. data/lib/xmpp4r/pubsub/children/items.rb +11 -2
  29. data/lib/xmpp4r/pubsub/children/publish.rb +14 -0
  30. data/lib/xmpp4r/pubsub/children/retract.rb +41 -0
  31. data/lib/xmpp4r/pubsub/helper/nodebrowser.rb +2 -3
  32. data/lib/xmpp4r/pubsub/helper/nodehelper.rb +4 -4
  33. data/lib/xmpp4r/pubsub/helper/oauth_service_helper.rb +90 -0
  34. data/lib/xmpp4r/pubsub/helper/servicehelper.rb +58 -19
  35. data/lib/xmpp4r/reliable.rb +168 -0
  36. data/lib/xmpp4r/rexmladdons.rb +6 -0
  37. data/lib/xmpp4r/roster/helper/roster.rb +5 -2
  38. data/lib/xmpp4r/sasl.rb +19 -8
  39. data/lib/xmpp4r/stream.rb +133 -31
  40. data/lib/xmpp4r/streamparser.rb +9 -1
  41. data/lib/xmpp4r/test/listener_mocker.rb +118 -0
  42. data/lib/xmpp4r/xmpp4r.rb +3 -1
  43. data/test/bytestreams/tc_ibb.rb +6 -4
  44. data/test/bytestreams/tc_socks5bytestreams.rb +3 -2
  45. data/test/caps/tc_helper.rb +4 -2
  46. data/test/dataforms/tc_data.rb +1 -1
  47. data/test/last/tc_helper.rb +75 -0
  48. data/test/lib/clienttester.rb +43 -14
  49. data/test/muc/tc_muc_mucclient.rb +6 -2
  50. data/test/pubsub/tc_helper.rb +131 -8
  51. data/test/pubsub/tc_nodeconfig.rb +7 -0
  52. data/test/reliable/tc_disconnect_cleanup.rb +334 -0
  53. data/test/reliable/tc_disconnect_exception.rb +37 -0
  54. data/test/reliable/tc_listener_mocked_test.rb +68 -0
  55. data/test/reliable/tc_reliable_connection.rb +31 -0
  56. data/test/roster/tc_helper.rb +21 -11
  57. data/test/rpc/tc_helper.rb +2 -2
  58. data/test/tc_callbacks.rb +3 -3
  59. data/test/tc_message.rb +15 -0
  60. data/test/tc_stream.rb +59 -121
  61. data/test/tc_streamError.rb +2 -4
  62. data/test/tc_streamparser.rb +26 -13
  63. data/test/ts_xmpp4r.rb +0 -9
  64. data/test/tune/tc_helper_recv.rb +0 -2
  65. data/test/vcard/tc_helper.rb +1 -1
  66. data/xmpp4r.gemspec +31 -84
  67. metadata +116 -167
  68. data/lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb.orig +0 -62
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift "#{File.dirname(__FILE__)}/../../lib"
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r'
7
+
8
+ class DisconnectExceptionTest < Test::Unit::TestCase
9
+ class Listener
10
+ def receive(element)
11
+ end
12
+ end
13
+
14
+ def test_streamparser
15
+ rd, wr = IO.pipe
16
+ listener = Listener.new
17
+ exception_raised = nil
18
+
19
+ Thread.new do
20
+ begin
21
+ parser = Jabber::StreamParser.new(rd, listener)
22
+ parser.parse
23
+ rescue => e
24
+ exception_raised = e
25
+ end
26
+ end
27
+
28
+ wr.write("<hi/>")
29
+ wr.close
30
+ sleep(0.1)
31
+
32
+ assert exception_raised
33
+ assert exception_raised.is_a?(Jabber::ServerDisconnected), "Expected a Jabber::ServerDisconnected but got #{exception_raised}"
34
+ # puts exception_raised.inspect
35
+ end
36
+
37
+ end
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift "#{File.dirname(__FILE__)}/../../lib"
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r'
7
+
8
+ # Jabber::debug = true
9
+
10
+ class ReliableListenerTest < Test::Unit::TestCase
11
+
12
+ class TestListener < Jabber::Reliable::Listener
13
+ attr_accessor :received_messages
14
+
15
+ def on_message(got_message)
16
+ self.received_messages ||= []
17
+ self.received_messages << got_message
18
+ end
19
+
20
+ end
21
+
22
+ def test_listener
23
+ listener = TestListener.new("listener1@localhost/hi", "test", {:servers => "127.0.0.1", :presence_message => "hi"})
24
+ Jabber::Test::ListenerMocker.mock_out(listener)
25
+ listener.start
26
+
27
+ message_to_send = Jabber::Message.new
28
+ message_to_send.to = "listener1@localhost/hi"
29
+ message_to_send.body = "hi"
30
+
31
+ listener.send_message(message_to_send)
32
+
33
+ assert_equal(1, listener.received_messages.size)
34
+
35
+ first_message = listener.received_messages[0]
36
+ assert_equal("hi", first_message.body)
37
+ listener.stop
38
+ end
39
+
40
+ def test_listener_stop_and_start
41
+ listener = TestListener.new("listener1@localhost/hi", "test", {:servers => "127.0.0.1", :presence_message => "hi"})
42
+ Jabber::Test::ListenerMocker.mock_out(listener)
43
+ listener.start
44
+
45
+ message_to_send = Jabber::Message.new
46
+ message_to_send.to = "listener1@localhost/hi"
47
+ message_to_send.body = "hi"
48
+
49
+ listener.send_message(message_to_send)
50
+
51
+ assert_equal(1, listener.received_messages.size)
52
+
53
+ first_message = listener.received_messages[0]
54
+ assert_equal("hi", first_message.body)
55
+ listener.stop
56
+
57
+ assert_raises(ArgumentError){
58
+ listener.send_message(message_to_send)
59
+ }
60
+
61
+ listener.start
62
+ listener.send_message(message_to_send)
63
+
64
+ assert_equal(2, listener.received_messages.size)
65
+ listener.stop
66
+ end
67
+
68
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift "#{File.dirname(__FILE__)}/../../lib"
4
+
5
+ require 'test/unit'
6
+ require 'xmpp4r'
7
+
8
+ # Jabber::debug = true
9
+
10
+ class ReliableConnectionTest < Test::Unit::TestCase
11
+
12
+ def test_connection_retry
13
+ @created_sockets = []
14
+ callback_proc = Proc.new do |socket_init_args|
15
+ @created_sockets << socket_init_args[0]
16
+ raise RuntimeError, "Fail to create socket"
17
+ end
18
+ Jabber::Test::ListenerMocker.with_socket_mocked(callback_proc) do
19
+ conn = Jabber::Reliable::Connection.new("listener1@localhost/hi", {
20
+ :servers => ["server 1", "server 2", "server 3", "server 4"],
21
+ :port => 12345,
22
+ :max_retry => 3, #3 retries = 4 total tries
23
+ :retry_sleep => 0.1})
24
+ assert_raises(RuntimeError) do
25
+ conn.connect
26
+ end
27
+ assert_equal(["server 1", "server 2", "server 3", "server 4"], @created_sockets.sort)
28
+ end
29
+ end
30
+
31
+ end
@@ -31,10 +31,11 @@ class Roster::HelperTest < Test::Unit::TestCase
31
31
  }
32
32
 
33
33
  query_waiter = Semaphore.new
34
- h = Roster::Helper.new(@client)
34
+ h = Roster::Helper.new(@client, false)
35
35
  h.add_query_callback { |iq|
36
36
  query_waiter.run
37
37
  }
38
+ h.get_roster
38
39
  wait_state
39
40
  query_waiter.wait
40
41
 
@@ -74,8 +75,9 @@ class Roster::HelperTest < Test::Unit::TestCase
74
75
  }
75
76
 
76
77
  query_waiter = Semaphore.new
77
- h = Roster::Helper.new(@client)
78
+ h = Roster::Helper.new(@client, false)
78
79
  h.add_query_callback { |iq| query_waiter.run }
80
+ h.get_roster
79
81
  wait_state
80
82
  query_waiter.wait
81
83
 
@@ -142,7 +144,7 @@ class Roster::HelperTest < Test::Unit::TestCase
142
144
 
143
145
  query_waiter = Semaphore.new
144
146
  presence_waiter = Semaphore.new
145
- h = Roster::Helper.new(@client)
147
+ h = Roster::Helper.new(@client, false)
146
148
  h.add_query_callback { |iq|
147
149
  query_waiter.run
148
150
  }
@@ -156,7 +158,7 @@ class Roster::HelperTest < Test::Unit::TestCase
156
158
  cb_item, cb_op, cb_p = item, oldpres, pres
157
159
  presence_waiter.run
158
160
  }
159
-
161
+ h.get_roster
160
162
  wait_state
161
163
  query_waiter.wait
162
164
 
@@ -289,8 +291,9 @@ class Roster::HelperTest < Test::Unit::TestCase
289
291
  }
290
292
 
291
293
  query_waiter = Semaphore.new
292
- h = Roster::Helper.new(@client)
294
+ h = Roster::Helper.new(@client, false)
293
295
  h.add_query_callback { |iq| query_waiter.run }
296
+ h.get_roster
294
297
  wait_state
295
298
  query_waiter.wait
296
299
 
@@ -326,8 +329,9 @@ class Roster::HelperTest < Test::Unit::TestCase
326
329
  }
327
330
 
328
331
  query_waiter = Semaphore.new
329
- h = Roster::Helper.new(@client)
332
+ h = Roster::Helper.new(@client, false)
330
333
  h.add_query_callback { |iq| query_waiter.run }
334
+ h.get_roster
331
335
  wait_state
332
336
  query_waiter.wait
333
337
 
@@ -362,15 +366,18 @@ class Roster::HelperTest < Test::Unit::TestCase
362
366
  end
363
367
 
364
368
  def test_decline_subscription
369
+ query_waiter = Semaphore.new
370
+
365
371
  state { |iq|
366
372
  send("<iq type='result' id='#{iq.id}'>
367
373
  <query xmlns='jabber:iq:roster'/>
368
374
  </iq>")
369
375
  }
370
376
 
371
- query_waiter = Semaphore.new
372
- h = Roster::Helper.new(@client)
377
+ h = Roster::Helper.new(@client, false)
373
378
  h.add_query_callback { |iq| query_waiter.run }
379
+ h.get_roster
380
+
374
381
  wait_state
375
382
  query_waiter.wait
376
383
 
@@ -406,8 +413,9 @@ class Roster::HelperTest < Test::Unit::TestCase
406
413
  }
407
414
 
408
415
  query_waiter = Semaphore.new
409
- h = Roster::Helper.new(@client)
416
+ h = Roster::Helper.new(@client, false)
410
417
  h.add_query_callback { query_waiter.run }
418
+ h.get_roster
411
419
  wait_state
412
420
  query_waiter.wait
413
421
 
@@ -434,8 +442,9 @@ class Roster::HelperTest < Test::Unit::TestCase
434
442
  }
435
443
 
436
444
  query_waiter = Semaphore.new
437
- h = Roster::Helper.new(@client)
445
+ h = Roster::Helper.new(@client, false)
438
446
  h.add_query_callback { query_waiter.run }
447
+ h.get_roster
439
448
  wait_state
440
449
  query_waiter.wait
441
450
 
@@ -474,11 +483,12 @@ class Roster::HelperTest < Test::Unit::TestCase
474
483
  update_args = nil
475
484
  update_waiter = Semaphore.new
476
485
 
477
- h = Roster::Helper.new(@client)
486
+ h = Roster::Helper.new(@client, false)
478
487
  h.add_update_callback { |*a|
479
488
  update_args = a
480
489
  update_waiter.run
481
490
  }
491
+ h.get_roster
482
492
 
483
493
  send("<iq type='set'>
484
494
  <query xmlns='jabber:iq:roster'>
@@ -78,7 +78,7 @@ class RPC::HelperTest < Test::Unit::TestCase
78
78
  assert_equal(['tseT', 'TEST'], cl.multicall(['reverse', 'Test'], ['upcase', 'Test']))
79
79
  end
80
80
 
81
- def test_100calls
81
+ def test_10calls
82
82
  give_client_jid!
83
83
 
84
84
  sv = RPC::Server.new(@server)
@@ -86,7 +86,7 @@ class RPC::HelperTest < Test::Unit::TestCase
86
86
 
87
87
  cl = RPC::Client.new(@client, 'a@b/c')
88
88
  correct = true
89
- 100.times {
89
+ 10.times {
90
90
  a, b = rand(1000), rand(1000)
91
91
  correct &&= (cl.call('add', a, b) == a + b)
92
92
  }
@@ -55,7 +55,7 @@ class CallbacksTest < Test::Unit::TestCase
55
55
  cbl.add(7, "ref1") { false }
56
56
  o = "o"
57
57
  assert(!cbl.process(o))
58
- end
58
+ end
59
59
 
60
60
  def test_callbacklist5
61
61
  cbl = CallbackList.new
@@ -63,7 +63,7 @@ class CallbacksTest < Test::Unit::TestCase
63
63
  cbl.add(7, "ref1") { false }
64
64
  o = "o"
65
65
  assert(cbl.process(o))
66
- end
66
+ end
67
67
 
68
68
  def test_callbacklist6
69
69
  cbl = CallbackList.new
@@ -78,7 +78,7 @@ class CallbacksTest < Test::Unit::TestCase
78
78
  }
79
79
  assert(!cbl.process(c, d))
80
80
  assert(ok)
81
- end
81
+ end
82
82
 
83
83
  def test_callbacklist7
84
84
  cbl = CallbackList.new
@@ -84,6 +84,21 @@ class MessageTest < Test::Unit::TestCase
84
84
  assert_equal('abc', x.thread)
85
85
  end
86
86
 
87
+ def test_chat_state
88
+ x = Message.new
89
+ assert_equal(nil, x.chat_state)
90
+ chat_state = REXML::Element.new('active')
91
+ chat_state.add_namespace('http://jabber.org/protocol/chatstates')
92
+ x.add(chat_state)
93
+ assert_equal(:active, x.chat_state)
94
+ x.chat_state = :gone
95
+ assert_equal(:gone, x.chat_state)
96
+ assert_raise(InvalidChatState) do
97
+ x.chat_state = :some_invalid_state
98
+ end
99
+ assert_equal true, x.gone?
100
+ end
101
+
87
102
  def test_error
88
103
  x = Message.new()
89
104
  assert_equal(nil, x.error)
@@ -1,36 +1,27 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  $:.unshift '../lib'
4
+ $:.unshift './lib/'
4
5
 
5
6
  require 'tempfile'
6
7
  require 'test/unit'
7
8
  require 'socket'
8
9
  require 'xmpp4r/stream'
9
10
  require 'xmpp4r/semaphore'
11
+ require 'clienttester'
10
12
  include Jabber
11
13
 
14
+ # Jabber::debug = true
15
+
12
16
  class StreamTest < Test::Unit::TestCase
13
- STREAM = '<stream:stream xmlns:stream="http://etherx.jabber.org/streams">'
14
-
15
- def setup
16
- @tmpfile = Tempfile.new("StreamSendTest")
17
- @tmpfilepath = @tmpfile.path()
18
- @tmpfile.unlink
19
- @servlisten = UNIXServer.new(@tmpfilepath)
20
- thServer = Thread.new { @server = @servlisten.accept }
21
- @iostream = UNIXSocket.new(@tmpfilepath)
17
+ include ClientTester
18
+
19
+ def busywait(&block)
22
20
  n = 0
23
- while not defined? @server and n < 10
24
- sleep 0.1
21
+ while not block.yield and n < 1000
22
+ Thread::pass
25
23
  n += 1
26
24
  end
27
- @stream = Stream.new
28
- @stream.start(@iostream)
29
- end
30
-
31
- def teardown
32
- @stream.close
33
- @server.close
34
25
  end
35
26
 
36
27
  ##
@@ -38,50 +29,43 @@ class StreamTest < Test::Unit::TestCase
38
29
  # stanzas to filters
39
30
  def test_process
40
31
  called = false
41
- @stream.add_xml_callback { called = true }
32
+ @client.add_xml_callback { called = true }
42
33
  assert(!called)
43
- @server.puts(STREAM)
44
- @server.flush
34
+ @server.send('<iq/>')
35
+ busywait { called }
45
36
  assert(called)
46
37
  end
47
38
 
48
- def test_process100
49
- @server.puts(STREAM)
50
- @server.flush
51
-
39
+ def test_process20
52
40
  done = Semaphore.new
53
41
  n = 0
54
- @stream.add_message_callback {
42
+ @client.add_message_callback {
55
43
  n += 1
56
- done.run if n % 100 == 0
44
+ done.run if n % 20 == 0
57
45
  }
58
46
 
59
- 100.times {
60
- @server.puts('<message/>')
61
- @server.flush
47
+ 20.times {
48
+ @server.send('<message/>')
62
49
  }
63
50
 
64
51
  done.wait
65
- assert_equal(100, n)
52
+ assert_equal(20, n)
66
53
 
67
- @server.puts('<message/>' * 100)
68
- @server.flush
54
+ @server.send('<message/>' * 20)
69
55
 
70
56
  done.wait
71
- assert_equal(200, n)
57
+ assert_equal(40, n)
72
58
  end
73
59
 
74
60
  def test_send
75
- @server.puts(STREAM)
76
- @server.flush
77
-
78
- Thread.new {
79
- assert_equal(Iq.new(:get).delete_namespace.to_s, @server.gets('>'))
80
- @stream.receive(Iq.new(:result))
61
+ sem = Semaphore::new
62
+ @server.add_xml_callback { |e|
63
+ @server.send(Iq.new(:result))
64
+ sem.run
81
65
  }
82
66
 
83
67
  called = 0
84
- @stream.send(Iq.new(:get)) { |reply|
68
+ @client.send(Iq.new(:get)) { |reply|
85
69
  called += 1
86
70
  if reply.kind_of? Iq and reply.type == :result
87
71
  true
@@ -89,45 +73,44 @@ class StreamTest < Test::Unit::TestCase
89
73
  false
90
74
  end
91
75
  }
92
-
76
+ sem.wait
77
+ busywait { called }
93
78
  assert_equal(1, called)
94
79
  end
95
80
 
96
81
  def test_send_nested
97
- @server.puts(STREAM)
98
- @server.flush
99
82
  finished = Semaphore.new
100
83
 
101
- Thread.new {
102
- assert_equal(Iq.new(:get).delete_namespace.to_s, @server.gets('>'))
103
- @server.puts(Iq.new(:result).set_id('1').delete_namespace.to_s)
104
- @server.flush
105
- assert_equal(Iq.new(:set).delete_namespace.to_s, @server.gets('>'))
106
- @server.puts(Iq.new(:result).set_id('2').delete_namespace.to_s)
107
- @server.flush
108
- assert_equal(Iq.new(:get).delete_namespace.to_s, @server.gets('>'))
109
- @server.puts(Iq.new(:result).set_id('3').delete_namespace.to_s)
110
- @server.flush
111
-
112
- finished.run
113
- }
84
+ id = 0
85
+ @server.add_xml_callback do |e|
86
+ id += 1
87
+ if id == 1
88
+ @server.send(Iq.new(:result).set_id('1').delete_namespace)
89
+ elsif id == 2
90
+ @server.send(Iq.new(:result).set_id('2').delete_namespace)
91
+ elsif id == 3
92
+ @server.send(Iq.new(:result).set_id('3').delete_namespace)
93
+ else
94
+ p e
95
+ end
96
+ end
114
97
 
115
98
  called_outer = 0
116
99
  called_inner = 0
117
100
 
118
- @stream.send(Iq.new(:get)) do |reply|
101
+ @client.send(Iq.new(:get)) do |reply|
119
102
  called_outer += 1
120
103
  assert_kind_of(Iq, reply)
121
104
  assert_equal(:result, reply.type)
122
105
 
123
106
  if reply.id == '1'
124
- @stream.send(Iq.new(:set)) do |reply2|
107
+ @client.send(Iq.new(:set)) do |reply2|
125
108
  called_inner += 1
126
109
  assert_kind_of(Iq, reply2)
127
110
  assert_equal(:result, reply2.type)
128
111
  assert_equal('2', reply2.id)
129
112
 
130
- @stream.send(Iq.new(:get))
113
+ @client.send(Iq.new(:get))
131
114
 
132
115
  true
133
116
  end
@@ -141,89 +124,44 @@ class StreamTest < Test::Unit::TestCase
141
124
 
142
125
  assert_equal(2, called_outer)
143
126
  assert_equal(1, called_inner)
144
-
145
- finished.wait
146
127
  end
147
128
 
148
129
  def test_send_in_callback
149
- @server.puts(STREAM)
150
- @server.flush
151
130
  finished = Semaphore.new
152
131
 
153
- @stream.add_message_callback {
154
- @stream.send_with_id(Iq.new(:get)) { |reply|
132
+ @client.add_message_callback {
133
+ @client.send_with_id(Iq.new(:get)) { |reply|
155
134
  assert_equal(:result, reply.type)
135
+ finished.run
156
136
  }
157
137
  }
158
138
 
159
- Thread.new {
160
- @server.gets('>')
161
- @server.puts(Iq.new(:result))
162
- finished.run
163
- }
164
-
165
- @server.puts(Message.new)
166
- finished.wait
167
- end
168
-
169
- def test_bidi
170
- @server.puts(STREAM)
171
- @server.flush
172
- finished = Semaphore.new
173
- ok = true
174
- n = 100
175
-
176
- Thread.new {
177
- n.times { |i|
178
- ok &&= (Iq.new(:get).set_id(i).delete_namespace.to_s == @server.gets('>'))
179
- @server.puts(Iq.new(:result).set_id(i).to_s)
180
- @server.flush
181
- }
182
-
183
- finished.run
184
- }
185
-
186
- n.times { |i|
187
- @stream.send(Iq.new(:get).set_id(i)) { |reply|
188
- ok &&= reply.kind_of? Iq
189
- ok &&= (:result == reply.type)
190
- ok &&= (i.to_s == reply.id)
191
- true
192
- }
139
+ @server.add_iq_callback { |iq|
140
+ @server.send(Iq.new(:result).set_id(iq.id))
193
141
  }
194
142
 
143
+ @server.send(Message.new)
195
144
  finished.wait
196
- assert(ok)
197
145
  end
198
146
 
199
147
  def test_similar_children
200
- delay = 0.1
201
148
  n = 0
202
- @stream.add_message_callback { n += 1 }
149
+ @client.add_message_callback { n += 1 }
203
150
  assert_equal(0, n)
204
- @server.puts("#{STREAM}<message/>")
205
- @server.flush
206
- sleep delay
151
+ @server.send("<message/>")
152
+ busywait { n == 1 }
207
153
  assert_equal(1, n)
208
- @server.puts('<message>')
209
- @server.flush
210
- sleep delay
154
+ @server.send('<message>')
211
155
  assert_equal(1, n)
212
- @server.puts('<message/>')
213
- @server.flush
214
- sleep delay
156
+ @server.send('<message/>')
215
157
  assert_equal(1, n)
216
- @server.puts('</message>')
217
- @server.flush
218
- sleep delay
158
+ @server.send('</message>')
159
+ busywait { n == 2 }
219
160
  assert_equal(2, n)
220
- @server.puts("<message>#{STREAM}<message/></stream:stream>")
221
- @server.flush
222
- sleep delay
161
+ @server.send("<message><stream:stream><message/></stream:stream>")
223
162
  assert_equal(2, n)
224
- @server.puts('</message>')
225
- @server.flush
226
- sleep delay
163
+ @server.send('</message>')
164
+ busywait { n == 3 }
227
165
  assert_equal(3, n)
228
166
  end
229
167
  end