@cryptotaxi247 / kubo / commits / ad1dc5f40

Corenet API: Use simple util instead of socat for tests

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed May 26, 2017 at 14:00 UTC ad1dc5f405e0470906447b13efa93a822f258d26
5 files changed +110 -16
test/bin/Rules.mk
+4
@@ -22,6 +22,10 @@ $(d)/go-timeout: test/dependencies/go-timeout
22 $(go-build)
23 TGTS_$(d) += $(d)/go-timeout
24
25 +$(d)/ma-pipe-unidir: test/dependencies/ma-pipe-unidir
26 + $(go-build)
27 +TGTS_$(d) += $(d)/ma-pipe-unidir
28 +
29 TGTS_GX_$(d) := hang-fds iptb
30 TGTS_GX_$(d) := $(addprefix $(d)/,$(TGTS_GX_$(d)))
31
test/dependencies/ma-pipe-unidir/LICENSE new
+22
@@ -0,0 +1,22 @@
1 +The MIT License (MIT)
2 +
3 +Copyright (c) 2017 Łukasz Magiera <magik6k@gmail.com>
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy
6 +of this software and associated documentation files (the "Software"), to deal
7 +in the Software without restriction, including without limitation the rights
8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom the Software is
10 +furnished to do so, subject to the following conditions:
11 +
12 +The above copyright notice and this permission notice shall be included in
13 +all copies or substantial portions of the Software.
14 +
15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 +THE SOFTWARE.
22 +
test/dependencies/ma-pipe-unidir/main.go new
+73
@@ -0,0 +1,73 @@
1 +package main
2 +
3 +import (
4 + "flag"
5 + "fmt"
6 +
7 + ma "github.com/multiformats/go-multiaddr"
8 + manet "github.com/multiformats/go-multiaddr-net"
9 + "io"
10 + "os"
11 +)
12 +
13 +const USAGE = "ma-pipe-unidir [-l|--listen] [-h|--help] <send|recv> <multiaddr>\n"
14 +
15 +type Opts struct {
16 + Listen bool
17 +}
18 +
19 +func main() {
20 + opts := Opts{}
21 + flag.BoolVar(&opts.Listen, "l", false, "")
22 + flag.BoolVar(&opts.Listen, "listen", false, "")
23 + flag.Usage = func() {
24 + fmt.Print(USAGE)
25 + }
26 + flag.Parse()
27 + args := flag.Args()
28 +
29 + if len(args) < 2 { // <mode> <addr>
30 + fmt.Print(USAGE)
31 + return
32 + }
33 +
34 + mode := args[0]
35 + addr := args[1]
36 +
37 + maddr, err := ma.NewMultiaddr(addr)
38 + if err != nil {
39 + return
40 + }
41 +
42 + var conn manet.Conn
43 +
44 + if opts.Listen {
45 + listener, err := manet.Listen(maddr)
46 + if err != nil {
47 + return
48 + }
49 +
50 + conn, err = listener.Accept()
51 + if err != nil {
52 + return
53 + }
54 + } else {
55 + var err error
56 + conn, err = manet.Dial(maddr)
57 + if err != nil {
58 + return
59 + }
60 + }
61 +
62 + defer conn.Close()
63 + switch mode {
64 + case "recv":
65 + io.Copy(os.Stdout, conn)
66 + case "send":
67 + io.Copy(conn, os.Stdin)
68 + default:
69 + //TODO: a bit late
70 + fmt.Print(USAGE)
71 + return
72 + }
73 +}
test/sharness/Rules.mk
+1 -1
@@ -7,7 +7,7 @@ T_$(d) = $(sort $(wildcard $(d)/t[0-9][0-9][0-9][0-9]-*.sh))
7
8 DEPS_$(d) := test/bin/random test/bin/multihash test/bin/pollEndpoint \
9 test/bin/iptb test/bin/go-sleep test/bin/random-files \
10 - test/bin/go-timeout test/bin/hang-fds
10 + test/bin/go-timeout test/bin/hang-fds test/bin/ma-pipe-unidir
11 DEPS_$(d) += cmd/ipfs/ipfs
12 DEPS_$(d) += $(d)/clean-test-results
13 DEPS_$(d) += $(SHARNESS_$(d))
test/sharness/t0180-corenet.sh
+10 -15
@@ -21,11 +21,6 @@ test_expect_success 'peer ids' '
21 PEERID_1=$(iptb get id 1)
22 '
23
24 -# netcat (nc) is needed for the following tests
25 -test_expect_success "socat is available" '
26 - type socat >/dev/null
27 -'
28 -
24 test_expect_success "test ports are closed" '
25 (! (netstat -ln | grep "LISTEN" | grep ":10101 ")) &&
26 (! (netstat -ln | grep "LISTEN" | grep ":10102 "))
@@ -36,22 +31,22 @@ test_expect_success 'start ipfs listener' '
31 '
32
33 test_expect_success 'Test server to client communications' '
39 - socat FILE:corenet0.bin TCP-LISTEN:10101,reuseaddr &
40 - NC_SERVER_PID=$!
34 + ma-pipe-unidir --listen send /ip4/127.0.0.1/tcp/10101 < corenet0.bin &
35 + SERVER_PID=$!
36
37 ipfsi 1 exp corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
43 - socat TCP4:127.0.0.1:10102 OPEN:client.out,creat,trunc &&
44 - wait $NC_SERVER_PID
38 + ma-pipe-unidir recv /ip4/127.0.0.1/tcp/10102 > client.out &&
39 + wait $SERVER_PID
40 '
41
47 -test_expect_success 'Test server to client communications' '
48 - socat TCP-LISTEN:10101,reuseaddr OPEN:server.out,creat,trunc &
49 - NC_SERVER_PID=$!
42 +test_expect_success 'Test client to server communications' '
43 + ma-pipe-unidir --listen recv /ip4/127.0.0.1/tcp/10101 > server.out &
44 + SERVER_PID=$!
45 + #sleep 0.5 &&
46
47 ipfsi 1 exp corenet dial $PEERID_0 corenet-test /ip4/127.0.0.1/tcp/10102 2>&1 > dialer-stdouterr.log &&
52 - socat FILE:corenet1.bin TCP4:127.0.0.1:10102 &&
53 -
54 - wait $NC_SERVER_PID
48 + ma-pipe-unidir send /ip4/127.0.0.1/tcp/10102 < corenet1.bin
49 + wait $SERVER_PID
50 '
51
52 test_expect_success 'server to client output looks good' '