anyt 0.8.2 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +4 -1
- data/lib/anyt/cli.rb +33 -7
- data/lib/anyt/client.rb +13 -7
- data/lib/anyt/command.rb +31 -18
- data/lib/anyt/config.rb +15 -7
- data/lib/anyt/dummy/application.rb +9 -11
- data/lib/anyt/dummy/config.ru +4 -0
- data/lib/anyt/dummy/routes.rb +4 -0
- data/lib/anyt/dummy/tmp/development_secret.txt +1 -0
- data/lib/anyt/ext/minitest.rb +23 -6
- data/lib/anyt/remote_control.rb +33 -0
- data/lib/anyt/rpc.rb +4 -6
- data/lib/anyt/tests.rb +5 -7
- data/lib/anyt/tests/core/ping_test.rb +2 -2
- data/lib/anyt/tests/core/welcome_test.rb +3 -3
- data/lib/anyt/tests/features/channel_state_test.rb +47 -0
- data/lib/anyt/tests/features/remote_disconnect_test.rb +30 -0
- data/lib/anyt/tests/features/server_restart_test.rb +28 -0
- data/lib/anyt/tests/request/channel_test.rb +28 -0
- data/lib/anyt/tests/request/connection_test.rb +23 -21
- data/lib/anyt/tests/request/disconnect_reasons_test.rb +23 -0
- data/lib/anyt/tests/request/disconnection_test.rb +50 -32
- data/lib/anyt/tests/streams/broadcast_test.rb +13 -13
- data/lib/anyt/tests/streams/multiple_clients_test.rb +10 -10
- data/lib/anyt/tests/streams/multiple_test.rb +10 -10
- data/lib/anyt/tests/streams/single_test.rb +35 -10
- data/lib/anyt/tests/streams/stop_test.rb +57 -0
- data/lib/anyt/tests/subscriptions/ack_test.rb +9 -11
- data/lib/anyt/tests/subscriptions/params_test.rb +6 -7
- data/lib/anyt/tests/subscriptions/perform_test.rb +16 -18
- data/lib/anyt/tests/subscriptions/transmissions_test.rb +6 -7
- data/lib/anyt/version.rb +1 -1
- metadata +32 -74
- data/.gitignore +0 -43
- data/.rubocop.yml +0 -80
- data/Gemfile +0 -6
- data/LICENSE.txt +0 -21
- data/Makefile +0 -5
- data/anyt.gemspec +0 -42
- data/circle.yml +0 -14
- 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 = {
|
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" => {
|
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
|
-
|
24
|
+
) do
|
25
25
|
ActionCable.server.broadcast(
|
26
26
|
"a",
|
27
|
-
data: {
|
27
|
+
data: {user_id: 1, status: "left", meta: {connection_time: "10s"}}
|
28
28
|
)
|
29
29
|
|
30
30
|
msg = {
|
31
|
-
"identifier" => {
|
31
|
+
"identifier" => {channel: channel}.to_json,
|
32
32
|
"message" => {
|
33
|
-
"data" => {
|
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
|
-
|
42
|
+
) do
|
43
43
|
ActionCable.server.broadcast("a", "<script>alert('Message!');</script>")
|
44
44
|
|
45
45
|
msg = {
|
46
|
-
"identifier" => {
|
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
|
-
|
55
|
+
) do
|
56
56
|
ActionCable.server.broadcast("a", '{"script":{"alert":"Message!"}}')
|
57
57
|
|
58
58
|
msg = {
|
59
|
-
"identifier" => {
|
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 = {
|
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" => {
|
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
|
-
|
28
|
+
) do
|
29
29
|
ActionCable.server.broadcast("a", data: "X")
|
30
30
|
|
31
|
-
msg = {
|
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
|
-
|
39
|
+
) do
|
40
40
|
ActionCable.server.broadcast("a", data: "X")
|
41
41
|
|
42
|
-
msg = {
|
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 = {
|
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 = {
|
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 = {
|
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" => {
|
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
|
-
|
25
|
+
) do
|
26
26
|
ActionCable.server.broadcast("a", data: "X")
|
27
27
|
|
28
|
-
msg = {
|
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 = {
|
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
|
-
|
41
|
+
) do
|
42
42
|
ActionCable.server.broadcast("a", data: "X")
|
43
43
|
|
44
|
-
msg = {
|
44
|
+
msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "X"}}
|
45
45
|
|
46
46
|
assert_equal msg, client.receive
|
47
47
|
|
48
|
-
unsubscribe_request = {
|
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 = {
|
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" => {
|
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
|
-
|
24
|
+
) do
|
25
25
|
ActionCable.server.broadcast("a", data: "X")
|
26
26
|
|
27
|
-
msg = {
|
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 = {
|
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
|
-
|
40
|
+
) do
|
41
41
|
ActionCable.server.broadcast("a", data: "X")
|
42
42
|
|
43
|
-
msg = {
|
43
|
+
msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "X"}}
|
44
44
|
|
45
45
|
assert_equal msg, client.receive
|
46
46
|
|
47
|
-
unsubscribe_request = {
|
47
|
+
unsubscribe_request = {command: "unsubscribe", identifier: {channel: channel}.to_json}
|
48
48
|
|
49
49
|
client.send(unsubscribe_request)
|
50
50
|
|
@@ -55,4 +55,29 @@ feature "Single stream" do
|
|
55
55
|
|
56
56
|
assert_raises(Anyt::Client::TimeoutError) { client.receive(timeout: 0.5) }
|
57
57
|
end
|
58
|
+
|
59
|
+
scenario %(
|
60
|
+
Client receives multiple messages when subscribed to the same channel
|
61
|
+
with different params
|
62
|
+
) do
|
63
|
+
subscribe_request = {command: "subscribe", identifier: {channel: channel, some_param: "test"}.to_json}
|
64
|
+
|
65
|
+
client.send(subscribe_request)
|
66
|
+
|
67
|
+
ack = {
|
68
|
+
"identifier" => {channel: channel, some_param: "test"}.to_json, "type" => "confirm_subscription"
|
69
|
+
}
|
70
|
+
|
71
|
+
assert_equal ack, client.receive
|
72
|
+
|
73
|
+
ActionCable.server.broadcast("a", data: "XX")
|
74
|
+
|
75
|
+
msg = {"identifier" => {channel: channel}.to_json, "message" => {"data" => "XX"}}
|
76
|
+
msg2 = {"identifier" => {channel: channel, some_param: "test"}.to_json, "message" => {"data" => "XX"}}
|
77
|
+
|
78
|
+
received = client.receive, client.receive
|
79
|
+
|
80
|
+
assert_includes received, msg
|
81
|
+
assert_includes received, msg2
|
82
|
+
end
|
58
83
|
end
|
@@ -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(
|
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
|
-
|
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" => {
|
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
|
-
|
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" => {
|
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
|
-
|
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" => {
|
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 = {
|
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" => {
|
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(
|
9
|
+
transmit("tock")
|
10
10
|
end
|
11
11
|
|
12
12
|
def echo(data)
|
13
|
-
transmit(response: data[
|
13
|
+
transmit(response: data["text"])
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
before do
|
18
|
-
subscribe_request = {
|
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" => {
|
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
|
-
|
32
|
-
|
31
|
+
) do
|
33
32
|
perform_request = {
|
34
|
-
command
|
35
|
-
identifier
|
36
|
-
"data" => {
|
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 = {
|
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
|
-
|
49
|
-
|
47
|
+
) do
|
50
48
|
perform_request = {
|
51
|
-
command
|
52
|
-
identifier
|
53
|
-
"data" => {
|
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 = {
|
56
|
+
msg = {"identifier" => {channel: channel}.to_json, "message" => {"response" => "hello"}}
|
59
57
|
|
60
58
|
assert_equal msg, client.receive
|
61
59
|
end
|