anyt 0.8.5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +4 -1
  4. data/lib/anyt/cli.rb +32 -6
  5. data/lib/anyt/client.rb +12 -7
  6. data/lib/anyt/command.rb +31 -18
  7. data/lib/anyt/config.rb +15 -7
  8. data/lib/anyt/dummy/application.rb +8 -6
  9. data/lib/anyt/dummy/config.ru +4 -0
  10. data/lib/anyt/dummy/tmp/development_secret.txt +1 -0
  11. data/lib/anyt/ext/minitest.rb +23 -6
  12. data/lib/anyt/remote_control.rb +33 -0
  13. data/lib/anyt/rpc.rb +4 -6
  14. data/lib/anyt/tests.rb +5 -7
  15. data/lib/anyt/tests/core/ping_test.rb +2 -2
  16. data/lib/anyt/tests/core/welcome_test.rb +2 -2
  17. data/lib/anyt/tests/features/channel_state_test.rb +47 -0
  18. data/lib/anyt/tests/features/remote_disconnect_test.rb +30 -0
  19. data/lib/anyt/tests/features/server_restart_test.rb +28 -0
  20. data/lib/anyt/tests/request/channel_test.rb +28 -0
  21. data/lib/anyt/tests/request/connection_test.rb +23 -21
  22. data/lib/anyt/tests/request/disconnect_reasons_test.rb +23 -0
  23. data/lib/anyt/tests/request/disconnection_test.rb +50 -32
  24. data/lib/anyt/tests/streams/broadcast_test.rb +13 -13
  25. data/lib/anyt/tests/streams/multiple_clients_test.rb +10 -10
  26. data/lib/anyt/tests/streams/multiple_test.rb +10 -10
  27. data/lib/anyt/tests/streams/single_test.rb +10 -10
  28. data/lib/anyt/tests/streams/stop_test.rb +57 -0
  29. data/lib/anyt/tests/subscriptions/ack_test.rb +9 -11
  30. data/lib/anyt/tests/subscriptions/params_test.rb +6 -7
  31. data/lib/anyt/tests/subscriptions/perform_test.rb +16 -18
  32. data/lib/anyt/tests/subscriptions/transmissions_test.rb +6 -7
  33. data/lib/anyt/version.rb +1 -1
  34. metadata +26 -68
  35. data/.gitignore +0 -43
  36. data/.rubocop.yml +0 -80
  37. data/Gemfile +0 -6
  38. data/LICENSE.txt +0 -21
  39. data/Makefile +0 -5
  40. data/anyt.gemspec +0 -42
  41. data/circle.yml +0 -14
  42. data/etc/tests/channel_broadcast_test.rb +0 -51
@@ -8,55 +8,55 @@ feature "Broadcast data to stream" do
8
8
  end
9
9
 
10
10
  before do
11
- subscribe_request = { command: "subscribe", identifier: { channel: channel }.to_json }
11
+ subscribe_request = {command: "subscribe", identifier: {channel: channel}.to_json}
12
12
 
13
13
  client.send(subscribe_request)
14
14
 
15
15
  ack = {
16
- "identifier" => { channel: channel }.to_json, "type" => "confirm_subscription"
16
+ "identifier" => {channel: channel}.to_json, "type" => "confirm_subscription"
17
17
  }
18
18
 
19
19
  assert_equal ack, client.receive
20
20
  end
21
21
 
22
- scenario %{
22
+ scenario %(
23
23
  Broadcast object
24
- } do
24
+ ) do
25
25
  ActionCable.server.broadcast(
26
26
  "a",
27
- data: { user_id: 1, status: "left", meta: { connection_time: "10s" } }
27
+ data: {user_id: 1, status: "left", meta: {connection_time: "10s"}}
28
28
  )
29
29
 
30
30
  msg = {
31
- "identifier" => { channel: channel }.to_json,
31
+ "identifier" => {channel: channel}.to_json,
32
32
  "message" => {
33
- "data" => { "user_id" => 1, "status" => "left", "meta" => { "connection_time" => "10s" } }
33
+ "data" => {"user_id" => 1, "status" => "left", "meta" => {"connection_time" => "10s"}}
34
34
  }
35
35
  }
36
36
 
37
37
  assert_equal msg, client.receive
38
38
  end
39
39
 
40
- scenario %{
40
+ scenario %(
41
41
  Broadcast custom string
42
- } do
42
+ ) do
43
43
  ActionCable.server.broadcast("a", "<script>alert('Message!');</script>")
44
44
 
45
45
  msg = {
46
- "identifier" => { channel: channel }.to_json,
46
+ "identifier" => {channel: channel}.to_json,
47
47
  "message" => "<script>alert('Message!');</script>"
48
48
  }
49
49
 
50
50
  assert_equal msg, client.receive
51
51
  end
52
52
 
53
- scenario %{
53
+ scenario %(
54
54
  Broadcast JSON string
55
- } do
55
+ ) do
56
56
  ActionCable.server.broadcast("a", '{"script":{"alert":"Message!"}}')
57
57
 
58
58
  msg = {
59
- "identifier" => { channel: channel }.to_json,
59
+ "identifier" => {channel: channel}.to_json,
60
60
  "message" => '{"script":{"alert":"Message!"}}'
61
61
  }
62
62
 
@@ -10,41 +10,41 @@ feature "Streams with many clients" do
10
10
  let(:client2) { build_client(ignore: %w[ping welcome]) }
11
11
 
12
12
  before do
13
- subscribe_request = { command: "subscribe", identifier: { channel: channel }.to_json }
13
+ subscribe_request = {command: "subscribe", identifier: {channel: channel}.to_json}
14
14
 
15
15
  client.send(subscribe_request)
16
16
  client2.send(subscribe_request)
17
17
 
18
18
  ack = {
19
- "identifier" => { channel: channel }.to_json, "type" => "confirm_subscription"
19
+ "identifier" => {channel: channel}.to_json, "type" => "confirm_subscription"
20
20
  }
21
21
 
22
22
  assert_equal ack, client.receive
23
23
  assert_equal ack, client2.receive
24
24
  end
25
25
 
26
- scenario %{
26
+ scenario %(
27
27
  Multiple clients receive messages from stream
28
- } do
28
+ ) do
29
29
  ActionCable.server.broadcast("a", data: "X")
30
30
 
31
- msg = { "identifier" => { channel: channel }.to_json, "message" => { "data" => "X" } }
31
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "X"}}
32
32
 
33
33
  assert_equal msg, client.receive
34
34
  assert_equal msg, client2.receive
35
35
  end
36
36
 
37
- scenario %{
37
+ scenario %(
38
38
  Client receive messages when another client removes subscription
39
- } do
39
+ ) do
40
40
  ActionCable.server.broadcast("a", data: "X")
41
41
 
42
- msg = { "identifier" => { channel: channel }.to_json, "message" => { "data" => "X" } }
42
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "X"}}
43
43
 
44
44
  assert_equal msg, client.receive
45
45
  assert_equal msg, client2.receive
46
46
 
47
- unsubscribe_request = { command: "unsubscribe", identifier: { channel: channel }.to_json }
47
+ unsubscribe_request = {command: "unsubscribe", identifier: {channel: channel}.to_json}
48
48
 
49
49
  client.send(unsubscribe_request)
50
50
 
@@ -53,7 +53,7 @@ feature "Streams with many clients" do
53
53
 
54
54
  ActionCable.server.broadcast("a", data: "Y")
55
55
 
56
- msg2 = { "identifier" => { channel: channel }.to_json, "message" => { "data" => "Y" } }
56
+ msg2 = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "Y"}}
57
57
 
58
58
  assert_equal msg2, client2.receive
59
59
  assert_raises(Anyt::Client::TimeoutError) { client.receive(timeout: 0.5) }
@@ -9,43 +9,43 @@ feature "Multiple streams" do
9
9
  end
10
10
 
11
11
  before do
12
- subscribe_request = { command: "subscribe", identifier: { channel: channel }.to_json }
12
+ subscribe_request = {command: "subscribe", identifier: {channel: channel}.to_json}
13
13
 
14
14
  client.send(subscribe_request)
15
15
 
16
16
  ack = {
17
- "identifier" => { channel: channel }.to_json, "type" => "confirm_subscription"
17
+ "identifier" => {channel: channel}.to_json, "type" => "confirm_subscription"
18
18
  }
19
19
 
20
20
  assert_equal ack, client.receive
21
21
  end
22
22
 
23
- scenario %{
23
+ scenario %(
24
24
  Client receives messages from both streams
25
- } do
25
+ ) do
26
26
  ActionCable.server.broadcast("a", data: "X")
27
27
 
28
- msg = { "identifier" => { channel: channel }.to_json, "message" => { "data" => "X" } }
28
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "X"}}
29
29
 
30
30
  assert_equal msg, client.receive
31
31
 
32
32
  ActionCable.server.broadcast("b", data: "Y")
33
33
 
34
- msg = { "identifier" => { channel: channel }.to_json, "message" => { "data" => "Y" } }
34
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "Y"}}
35
35
 
36
36
  assert_equal msg, client.receive
37
37
  end
38
38
 
39
- scenario %{
39
+ scenario %(
40
40
  Client does not receive messages from any stream after removing subscription
41
- } do
41
+ ) do
42
42
  ActionCable.server.broadcast("a", data: "X")
43
43
 
44
- msg = { "identifier" => { channel: channel }.to_json, "message" => { "data" => "X" } }
44
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "X"}}
45
45
 
46
46
  assert_equal msg, client.receive
47
47
 
48
- unsubscribe_request = { command: "unsubscribe", identifier: { channel: channel }.to_json }
48
+ unsubscribe_request = {command: "unsubscribe", identifier: {channel: channel}.to_json}
49
49
 
50
50
  client.send(unsubscribe_request)
51
51
 
@@ -8,43 +8,43 @@ feature "Single stream" do
8
8
  end
9
9
 
10
10
  before do
11
- subscribe_request = { command: "subscribe", identifier: { channel: channel }.to_json }
11
+ subscribe_request = {command: "subscribe", identifier: {channel: channel}.to_json}
12
12
 
13
13
  client.send(subscribe_request)
14
14
 
15
15
  ack = {
16
- "identifier" => { channel: channel }.to_json, "type" => "confirm_subscription"
16
+ "identifier" => {channel: channel}.to_json, "type" => "confirm_subscription"
17
17
  }
18
18
 
19
19
  assert_equal ack, client.receive
20
20
  end
21
21
 
22
- scenario %{
22
+ scenario %(
23
23
  Client receives messages from the stream
24
- } do
24
+ ) do
25
25
  ActionCable.server.broadcast("a", data: "X")
26
26
 
27
- msg = { "identifier" => { channel: channel }.to_json, "message" => { "data" => "X" } }
27
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "X"}}
28
28
 
29
29
  assert_equal msg, client.receive
30
30
 
31
31
  ActionCable.server.broadcast("a", data: "Y")
32
32
 
33
- msg = { "identifier" => { channel: channel }.to_json, "message" => { "data" => "Y" } }
33
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "Y"}}
34
34
 
35
35
  assert_equal msg, client.receive
36
36
  end
37
37
 
38
- scenario %{
38
+ scenario %(
39
39
  Client does not receive messages from the stream after removing subscription
40
- } do
40
+ ) do
41
41
  ActionCable.server.broadcast("a", data: "X")
42
42
 
43
- msg = { "identifier" => { channel: channel }.to_json, "message" => { "data" => "X" } }
43
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "X"}}
44
44
 
45
45
  assert_equal msg, client.receive
46
46
 
47
- unsubscribe_request = { command: "unsubscribe", identifier: { channel: channel }.to_json }
47
+ unsubscribe_request = {command: "unsubscribe", identifier: {channel: channel}.to_json}
48
48
 
49
49
  client.send(unsubscribe_request)
50
50
 
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ feature "Stop streams" do
4
+ channel do
5
+ def subscribed
6
+ stream_from "a"
7
+ stream_from "b"
8
+ end
9
+
10
+ def ping(data)
11
+ ActionCable.server.broadcast data["name"], reply: "pong"
12
+ end
13
+
14
+ def unfollow(data)
15
+ stop_stream_from data["name"]
16
+ end
17
+ end
18
+
19
+ before do
20
+ subscribe_request = {command: "subscribe", identifier: {channel: channel}.to_json}
21
+
22
+ client.send(subscribe_request)
23
+
24
+ ack = {
25
+ "identifier" => {channel: channel}.to_json, "type" => "confirm_subscription"
26
+ }
27
+
28
+ assert_equal ack, client.receive
29
+ end
30
+
31
+ scenario %(
32
+ Client unsubscribes from the stream
33
+ ) do
34
+ skip if Anyt.config.use_action_cable && (::ActionCable::VERSION::MAJOR < 6 || ::ActionCable::VERSION::MINOR < 1)
35
+
36
+ ActionCable.server.broadcast("a", data: "X")
37
+
38
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "X"}}
39
+
40
+ assert_equal msg, client.receive
41
+
42
+ perform_request = {
43
+ :command => "message",
44
+ :identifier => {channel: channel}.to_json,
45
+ "data" => {"action" => "unfollow", "name" => "a"}.to_json
46
+ }
47
+ client.send(perform_request)
48
+ sleep 0.2 # give some time to commit unsubscribe
49
+
50
+ ActionCable.server.broadcast("a", data: "Y")
51
+ sleep 0.2 # "a" should be broadcasted first
52
+ ActionCable.server.broadcast("b", data: "Z")
53
+
54
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "Z"}}
55
+ assert_equal msg, client.receive
56
+ end
57
+ end
@@ -3,37 +3,35 @@
3
3
  feature "Subscription aknowledgement" do
4
4
  channel
5
5
 
6
- channel('rejector') do
6
+ channel("rejector") do
7
7
  def subscribed
8
8
  reject
9
9
  end
10
10
  end
11
11
 
12
- scenario %{
12
+ scenario %(
13
13
  Client receives subscription confirmation
14
- } do
15
-
16
- subscribe_request = { command: "subscribe", identifier: { channel: channel }.to_json }
14
+ ) do
15
+ subscribe_request = {command: "subscribe", identifier: {channel: channel}.to_json}
17
16
 
18
17
  client.send(subscribe_request)
19
18
 
20
19
  ack = {
21
- "identifier" => { channel: channel }.to_json, "type" => "confirm_subscription"
20
+ "identifier" => {channel: channel}.to_json, "type" => "confirm_subscription"
22
21
  }
23
22
 
24
23
  assert_equal ack, client.receive
25
24
  end
26
25
 
27
- scenario %{
26
+ scenario %(
28
27
  Client receives subscription rejection
29
- } do
30
-
31
- subscribe_request = { command: "subscribe", identifier: { channel: rejector_channel }.to_json }
28
+ ) do
29
+ subscribe_request = {command: "subscribe", identifier: {channel: rejector_channel}.to_json}
32
30
 
33
31
  client.send(subscribe_request)
34
32
 
35
33
  ack = {
36
- "identifier" => { channel: rejector_channel }.to_json, "type" => "reject_subscription"
34
+ "identifier" => {channel: rejector_channel}.to_json, "type" => "reject_subscription"
37
35
  }
38
36
 
39
37
  assert_equal ack, client.receive
@@ -3,26 +3,25 @@
3
3
  feature "Subscription with params" do
4
4
  channel
5
5
 
6
- scenario %{
6
+ scenario %(
7
7
  Client subscribes to the same channel with different params
8
- } do
9
-
10
- subscribe_request = { command: "subscribe", identifier: { channel: channel, id: 1 }.to_json }
8
+ ) do
9
+ subscribe_request = {command: "subscribe", identifier: {channel: channel, id: 1}.to_json}
11
10
 
12
11
  client.send(subscribe_request)
13
12
 
14
13
  ack = {
15
- "identifier" => { channel: channel, id: 1 }.to_json, "type" => "confirm_subscription"
14
+ "identifier" => {channel: channel, id: 1}.to_json, "type" => "confirm_subscription"
16
15
  }
17
16
 
18
17
  assert_equal ack, client.receive
19
18
 
20
- subscribe_request_2 = { command: "subscribe", identifier: { channel: channel, id: 2 }.to_json }
19
+ subscribe_request_2 = {command: "subscribe", identifier: {channel: channel, id: 2}.to_json}
21
20
 
22
21
  client.send(subscribe_request_2)
23
22
 
24
23
  ack = {
25
- "identifier" => { channel: channel, id: 2 }.to_json, "type" => "confirm_subscription"
24
+ "identifier" => {channel: channel, id: 2}.to_json, "type" => "confirm_subscription"
26
25
  }
27
26
 
28
27
  assert_equal ack, client.receive
@@ -6,56 +6,54 @@ using Anyt::AsyncHelpers
6
6
  feature "Subscription perform methods" do
7
7
  channel do
8
8
  def tick
9
- transmit('tock')
9
+ transmit("tock")
10
10
  end
11
11
 
12
12
  def echo(data)
13
- transmit(response: data['text'])
13
+ transmit(response: data["text"])
14
14
  end
15
15
  end
16
16
 
17
17
  before do
18
- subscribe_request = { command: "subscribe", identifier: { channel: channel }.to_json }
18
+ subscribe_request = {command: "subscribe", identifier: {channel: channel}.to_json}
19
19
 
20
20
  client.send(subscribe_request)
21
21
 
22
22
  ack = {
23
- "identifier" => { channel: channel }.to_json, "type" => "confirm_subscription"
23
+ "identifier" => {channel: channel}.to_json, "type" => "confirm_subscription"
24
24
  }
25
25
 
26
26
  assert_equal ack, client.receive
27
27
  end
28
28
 
29
- scenario %{
29
+ scenario %(
30
30
  Client perform actions without arguments
31
- } do
32
-
31
+ ) do
33
32
  perform_request = {
34
- command: "message",
35
- identifier: { channel: channel }.to_json,
36
- "data" => { "action" => "tick" }.to_json
33
+ :command => "message",
34
+ :identifier => {channel: channel}.to_json,
35
+ "data" => {"action" => "tick"}.to_json
37
36
  }
38
37
 
39
38
  client.send(perform_request)
40
39
 
41
- msg = { "identifier" => { channel: channel }.to_json, "message" => "tock" }
40
+ msg = {"identifier" => {channel: channel}.to_json, "message" => "tock"}
42
41
 
43
42
  assert_equal msg, client.receive
44
43
  end
45
44
 
46
- scenario %{
45
+ scenario %(
47
46
  Client perform actions with arguments
48
- } do
49
-
47
+ ) do
50
48
  perform_request = {
51
- command: "message",
52
- identifier: { channel: channel }.to_json,
53
- "data" => { "action" => "echo", "text" => "hello" }.to_json
49
+ :command => "message",
50
+ :identifier => {channel: channel}.to_json,
51
+ "data" => {"action" => "echo", "text" => "hello"}.to_json
54
52
  }
55
53
 
56
54
  client.send(perform_request)
57
55
 
58
- msg = { "identifier" => { channel: channel }.to_json, "message" => { "response" => "hello" } }
56
+ msg = {"identifier" => {channel: channel}.to_json, "message" => {"response" => "hello"}}
59
57
 
60
58
  assert_equal msg, client.receive
61
59
  end