async 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,71 +0,0 @@
1
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- RSpec.describe Async::Reactor do
22
- include_context "closes all io"
23
-
24
- # Shared port for localhost network tests.
25
- let(:server_address) {Addrinfo.udp("127.0.0.1", 6778)}
26
- let(:data) {"The quick brown fox jumped over the lazy dog."}
27
-
28
- describe 'basic udp server' do
29
- it "should echo data back to peer" do
30
- subject.async do
31
- Async::Socket.bind(server_address) do |server|
32
- packet, address = server.recvfrom(512)
33
-
34
- server.send(packet, 0, address)
35
- end
36
- end
37
-
38
- subject.async do
39
- Async::Socket.connect(server_address) do |client|
40
- client.send(data)
41
- response = client.recv(512)
42
-
43
- expect(response).to be == data
44
- end
45
- end
46
-
47
- subject.run
48
- end
49
-
50
- it "should use unconnected socket" do
51
- subject.async do
52
- Async::Socket.bind(server_address) do |server|
53
- packet, address = server.recvfrom(512)
54
-
55
- server.send(packet, 0, address)
56
- end
57
- end
58
-
59
- subject.async do |task|
60
- task.with(UDPSocket.new(server_address.afamily)) do |client|
61
- client.send(data, 0, server_address)
62
- response, address = client.recvfrom(512)
63
-
64
- expect(response).to be == data
65
- end
66
- end
67
-
68
- subject.run
69
- end
70
- end
71
- end
@@ -1,53 +0,0 @@
1
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'async/unix_socket'
22
-
23
- RSpec.describe Async::Reactor do
24
- include_context "closes all io"
25
-
26
- let(:path) {File.join(__dir__, "unix-socket")}
27
- let(:data) {"The quick brown fox jumped over the lazy dog."}
28
-
29
- before(:each) do
30
- FileUtils.rm_f path
31
- end
32
-
33
- describe 'basic unix socket' do
34
- it "should echo data back to peer" do
35
- subject.async do |task|
36
- task.with(UNIXServer.new(path)) do |server|
37
- task.with(server.accept) do |peer|
38
- peer.send(peer.recv(512))
39
- end
40
- end
41
- end
42
-
43
- subject.with(UNIXSocket.new(path)) do |socket|
44
- socket.send(data)
45
- response = socket.recv(512)
46
-
47
- expect(response).to be == data
48
- end
49
-
50
- subject.run
51
- end
52
- end
53
- end