Commit 5e8725db authored by Łukasz Magiera's avatar Łukasz Magiera

p2p: test to ensure closing right linsters

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent 4c98edaf
......@@ -338,8 +338,15 @@ var p2pCloseCmd = &cmds.Command{
}
n.P2P.Listeners.Unlock()
var errs []string
for _, l := range todo {
l.Close()
if err := l.Close(); err != nil {
errs = append(errs, err.Error())
}
}
if len(errs) != 0 {
res.SetError(fmt.Errorf("errors when closing streams: %s", strings.Join(errs, "; ")), cmdkit.ErrNormal)
return
}
res.SetOutput(len(todo))
......
......@@ -109,8 +109,7 @@ func (l *localListener) Close() error {
return err
}
if ok {
l.listener.Close()
l.listener = nil
return l.listener.Close()
}
return nil
}
......
......@@ -233,16 +233,27 @@ test_expect_success "'ipfs p2p close' closes app numeric handlers" '
test_must_be_empty actual
'
test_expect_success "'ipfs p2p close' closes by listen addr" '
test_expect_success "'ipfs p2p close' closes by target addr" '
ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p close -l /ipfs/$PEERID_0 &&
ipfsi 0 p2p close -t /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p ls > actual &&
test_must_be_empty actual
'
test_expect_success "'ipfs p2p close' closes by target addr" '
test_expect_success "'ipfs p2p close' closes right listeners" '
ipfsi 0 p2p listen /x/p2p-test /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p close -t /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p forward /x/p2p-test /ip4/127.0.0.1/tcp/10101 /ipfs/$PEERID_1 &&
echo "/x/p2p-test /ipfs/$PEERID_0 /ip4/127.0.0.1/tcp/10101" > expected &&
ipfsi 0 p2p close -l /ip4/127.0.0.1/tcp/10101 &&
ipfsi 0 p2p ls > actual &&
test_cmp expected actual
'
check_test_ports
test_expect_success "'ipfs p2p close' closes by listen addr" '
ipfsi 0 p2p close -l /ipfs/$PEERID_0 &&
ipfsi 0 p2p ls > actual &&
test_must_be_empty actual
'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment